Refactor
This commit is contained in:
parent
4c921759ef
commit
18d84727ab
@ -18,19 +18,6 @@ SOURCES += \
|
|||||||
comdel/parser/sourceerror.cpp \
|
comdel/parser/sourceerror.cpp \
|
||||||
comdel/parser/token.cpp \
|
comdel/parser/token.cpp \
|
||||||
comdel/parser/tokenstype.cpp \
|
comdel/parser/tokenstype.cpp \
|
||||||
domain/display/display.cpp \
|
|
||||||
domain/display/displayitem.cpp \
|
|
||||||
domain/library/addressspace.cpp \
|
|
||||||
domain/library/attribute.cpp \
|
|
||||||
domain/library/bus.cpp \
|
|
||||||
domain/library/component.cpp \
|
|
||||||
domain/library/connection.cpp \
|
|
||||||
domain/library/library.cpp \
|
|
||||||
domain/library/pin.cpp \
|
|
||||||
domain/library/popup.cpp \
|
|
||||||
domain/library/rule.cpp \
|
|
||||||
domain/library/value.cpp \
|
|
||||||
domain/library/wire.cpp \
|
|
||||||
domain/schema/connectioninstance.cpp \
|
domain/schema/connectioninstance.cpp \
|
||||||
domain/schema/instance.cpp \
|
domain/schema/instance.cpp \
|
||||||
domain/schema/instanceattribute.cpp \
|
domain/schema/instanceattribute.cpp \
|
||||||
@ -52,19 +39,6 @@ HEADERS += \
|
|||||||
comdel/parser/sourceerror.h \
|
comdel/parser/sourceerror.h \
|
||||||
comdel/parser/token.h \
|
comdel/parser/token.h \
|
||||||
comdel/parser/tokenstype.h \
|
comdel/parser/tokenstype.h \
|
||||||
domain/display/display.h \
|
|
||||||
domain/display/displayitem.h \
|
|
||||||
domain/library/addressspace.h \
|
|
||||||
domain/library/attribute.h \
|
|
||||||
domain/library/bus.h \
|
|
||||||
domain/library/component.h \
|
|
||||||
domain/library/connection.h \
|
|
||||||
domain/library/library.h \
|
|
||||||
domain/library/pin.h \
|
|
||||||
domain/library/popup.h \
|
|
||||||
domain/library/rule.h \
|
|
||||||
domain/library/value.h \
|
|
||||||
domain/library/wire.h \
|
|
||||||
domain/schema/connectioninstance.h \
|
domain/schema/connectioninstance.h \
|
||||||
domain/schema/instance.h \
|
domain/schema/instance.h \
|
||||||
domain/schema/instanceattribute.h \
|
domain/schema/instanceattribute.h \
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define ASTNODE_H
|
#define ASTNODE_H
|
||||||
|
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include <optional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AST base class, all AST node classes extand this class. Class contains basic
|
* AST base class, all AST node classes extand this class. Class contains basic
|
||||||
@ -26,26 +28,24 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StringNode: public AstNode {
|
struct StringNode: public AstNode
|
||||||
public:
|
{
|
||||||
std::string value;
|
std::string value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IdentifierNode: public AstNode
|
||||||
class IdentifierNode: public AstNode {
|
{
|
||||||
public:
|
|
||||||
std::string value;
|
std::string value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NumberNode: public AstNode {
|
struct NumberNode: public AstNode {
|
||||||
public:
|
|
||||||
long long int value;
|
long long int value;
|
||||||
NumberNode(std::string expression);
|
NumberNode(std::string expression);
|
||||||
NumberNode(): value(0) {}
|
NumberNode(): value(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CountNode: public AstNode {
|
struct CountNode: public AstNode
|
||||||
public:
|
{
|
||||||
NumberNode first;
|
NumberNode first;
|
||||||
NumberNode second;
|
NumberNode second;
|
||||||
|
|
||||||
@ -53,4 +53,292 @@ public:
|
|||||||
CountNode() {}
|
CountNode() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct AddressSpace: public AstNode
|
||||||
|
{
|
||||||
|
IdentifierNode name;
|
||||||
|
NumberNode start;
|
||||||
|
NumberNode end;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Value: AstNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum ValueType {
|
||||||
|
INT,
|
||||||
|
STRING,
|
||||||
|
BOOL,
|
||||||
|
IDENTIFIER
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
ValueType type;
|
||||||
|
std::optional<long long> intValue;
|
||||||
|
std::optional<std::string> stringValue;
|
||||||
|
std::optional<bool> boolValue;
|
||||||
|
std::optional<std::string> identifierValue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ValueType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
long long asInt() {
|
||||||
|
if(is(INT)) {
|
||||||
|
return intValue.value();
|
||||||
|
}
|
||||||
|
throw "cannot convert type to int";
|
||||||
|
}
|
||||||
|
std::string asString() {
|
||||||
|
if(is(STRING)) {
|
||||||
|
return stringValue.value();
|
||||||
|
}
|
||||||
|
throw "cannot convert type to string";
|
||||||
|
}
|
||||||
|
std::string asIdentifier() {
|
||||||
|
if(is(IDENTIFIER)) {
|
||||||
|
return identifierValue.value();
|
||||||
|
}
|
||||||
|
throw "cannot convert type to identifier";
|
||||||
|
}
|
||||||
|
bool asBool() {
|
||||||
|
if(is(BOOL)) {
|
||||||
|
return boolValue.value();
|
||||||
|
}
|
||||||
|
throw "cannot convert type to bool";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is(ValueType type) {
|
||||||
|
return this->type == type;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Value ofBool(bool _value) {
|
||||||
|
Value value;
|
||||||
|
value.type = BOOL;
|
||||||
|
value.boolValue = std::optional<bool>(_value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Value ofInt(long long _value) {
|
||||||
|
Value value;
|
||||||
|
value.type = INT;
|
||||||
|
value.intValue = std::optional<long long>(_value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Value ofString(std::string _value) {
|
||||||
|
Value value;
|
||||||
|
value.type = STRING;
|
||||||
|
value.stringValue = std::optional<std::string>(_value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Value ofIdentifier(std::string _value) {
|
||||||
|
Value value;
|
||||||
|
value.type = IDENTIFIER;
|
||||||
|
value.identifierValue = std::optional<std::string>(_value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Condition
|
||||||
|
{
|
||||||
|
bool negated;
|
||||||
|
IdentifierNode functionName;
|
||||||
|
std::vector<Value> params;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Action: AstNode {
|
||||||
|
public:
|
||||||
|
enum ActionType {
|
||||||
|
ERROR,
|
||||||
|
WARNING
|
||||||
|
};
|
||||||
|
|
||||||
|
ActionType type;
|
||||||
|
StringNode message;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct IfStmt: AstNode
|
||||||
|
{
|
||||||
|
Condition condition;
|
||||||
|
Action action;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Rule: AstNode
|
||||||
|
{
|
||||||
|
std::vector<IfStmt> statements;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct EnumerationNode: AstNode
|
||||||
|
{
|
||||||
|
StringNode key;
|
||||||
|
Value value;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Popup: AstNode
|
||||||
|
{
|
||||||
|
enum PopupType {
|
||||||
|
AUTOMATIC,
|
||||||
|
ON_DEMAND
|
||||||
|
};
|
||||||
|
|
||||||
|
PopupType type;
|
||||||
|
StringNode title;
|
||||||
|
StringNode text;
|
||||||
|
|
||||||
|
bool enumerated;
|
||||||
|
std::vector<EnumerationNode> enumeration;
|
||||||
|
|
||||||
|
std::vector<Rule> rules;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PropertyNode: public AstNode
|
||||||
|
{
|
||||||
|
IdentifierNode key;
|
||||||
|
Value value;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct DisplayItemNode: AstNode
|
||||||
|
{
|
||||||
|
IdentifierNode type;
|
||||||
|
std::vector<PropertyNode> values;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct DisplayNode: AstNode
|
||||||
|
{
|
||||||
|
std::vector<DisplayItemNode> items;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct PinConnectionNode: AstNode
|
||||||
|
{
|
||||||
|
enum ConnectionType {
|
||||||
|
CHECK_ONLY,
|
||||||
|
AUTOMATICALLY
|
||||||
|
};
|
||||||
|
|
||||||
|
StringNode message;
|
||||||
|
ConnectionType type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct PinNode: AstNode
|
||||||
|
{
|
||||||
|
enum PinType {
|
||||||
|
IN_OUT,
|
||||||
|
IN,
|
||||||
|
OUT
|
||||||
|
};
|
||||||
|
|
||||||
|
IdentifierNode name;
|
||||||
|
PinType type;
|
||||||
|
StringNode tooltip;
|
||||||
|
|
||||||
|
PinConnectionNode connection;
|
||||||
|
|
||||||
|
DisplayNode display;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct WireNode: public AstNode
|
||||||
|
{
|
||||||
|
enum WireType {
|
||||||
|
WIRE,
|
||||||
|
WIRED_AND,
|
||||||
|
WIRED_OR,
|
||||||
|
R_WIRE
|
||||||
|
};
|
||||||
|
WireType type;
|
||||||
|
IdentifierNode name;
|
||||||
|
NumberNode size;
|
||||||
|
/*
|
||||||
|
bool isTerminatedWith;
|
||||||
|
long terminatedWith;
|
||||||
|
|
||||||
|
bool isIfUntrminated;
|
||||||
|
long ifUnterminated;
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct AttributeNode: AstNode
|
||||||
|
{
|
||||||
|
Value::ValueType type;
|
||||||
|
IdentifierNode name;
|
||||||
|
std::optional<Value> defaultValue;
|
||||||
|
std::optional<Popup> popup;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ConnectionNode: AstNode
|
||||||
|
{
|
||||||
|
IdentifierNode component;
|
||||||
|
IdentifierNode pin;
|
||||||
|
IdentifierNode bus;
|
||||||
|
std::vector<AttributeNode> attributes;
|
||||||
|
std::vector<IdentifierNode> wires;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct ComponentNode: AstNode
|
||||||
|
{
|
||||||
|
enum ComponentType {
|
||||||
|
OTHER,
|
||||||
|
PROCESSOR,
|
||||||
|
MEMORY
|
||||||
|
};
|
||||||
|
|
||||||
|
IdentifierNode name;
|
||||||
|
StringNode tooltip;
|
||||||
|
StringNode source;
|
||||||
|
ComponentType type;
|
||||||
|
std::vector<Rule> rules;
|
||||||
|
StringNode instanceName;
|
||||||
|
CountNode count;
|
||||||
|
DisplayNode display;
|
||||||
|
std::vector<PinNode> pin;
|
||||||
|
std::vector<AttributeNode> attributes;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct BusNode: AstNode
|
||||||
|
{
|
||||||
|
enum BusType {
|
||||||
|
AUTOMATIC,
|
||||||
|
REGULAR
|
||||||
|
};
|
||||||
|
|
||||||
|
BusType type;
|
||||||
|
IdentifierNode name;
|
||||||
|
StringNode tooltip;
|
||||||
|
CountNode count;
|
||||||
|
DisplayNode display;
|
||||||
|
|
||||||
|
std::vector<WireNode> wires;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LibraryNode: AstNode
|
||||||
|
{
|
||||||
|
StringNode name;
|
||||||
|
StringNode libraryInfo;
|
||||||
|
StringNode header;
|
||||||
|
StringNode componentDirectory;
|
||||||
|
|
||||||
|
std::vector<AddressSpace> addressSpaces;
|
||||||
|
|
||||||
|
std::vector<ComponentNode> components;
|
||||||
|
std::vector<BusNode> buses;
|
||||||
|
std::vector<ConnectionNode> connections;
|
||||||
|
|
||||||
|
std::vector<PropertyNode> messages;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // ASTNODE_H
|
#endif // ASTNODE_H
|
||||||
|
@ -207,11 +207,11 @@ Spanner ComdelParser::getSpanner()
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
std::optional<Library> ComdelParser::parse()
|
std::optional<LibraryNode> ComdelParser::parse()
|
||||||
{
|
{
|
||||||
|
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
Library library{};
|
LibraryNode library{};
|
||||||
|
|
||||||
while ( ! check(TokenType::END_OF_FILE) ) {
|
while ( ! check(TokenType::END_OF_FILE) ) {
|
||||||
PResult<poly<AstNode>> err;
|
PResult<poly<AstNode>> err;
|
||||||
@ -398,14 +398,14 @@ PResult<AddressSpace> ComdelParser::parseAddress()
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Component := "@component" + IDENTIFIER + ("processor" | "memory") { COMPONENT_BLOCK }
|
* ComponentNode := "@component" + IDENTIFIER + ("processor" | "memory") { COMPONENT_BLOCK }
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Component> ComdelParser::parseComponent()
|
PResult<ComponentNode> ComdelParser::parseComponent()
|
||||||
{
|
{
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
|
|
||||||
Component component{};
|
ComponentNode component{};
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_COMPONENT);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_COMPONENT);
|
||||||
|
|
||||||
@ -413,12 +413,12 @@ PResult<Component> ComdelParser::parseComponent()
|
|||||||
|
|
||||||
if(check(TokenType::CT_PROCESSOR)) {
|
if(check(TokenType::CT_PROCESSOR)) {
|
||||||
bump();
|
bump();
|
||||||
component.type = Component::PROCESSOR;
|
component.type = ComponentNode::PROCESSOR;
|
||||||
} else if(check(TokenType::CT_MEMORY)) {
|
} else if(check(TokenType::CT_MEMORY)) {
|
||||||
bump();
|
bump();
|
||||||
component.type = Component::MEMORY;
|
component.type = ComponentNode::MEMORY;
|
||||||
} else {
|
} else {
|
||||||
component.type = Component::OTHER;
|
component.type = ComponentNode::OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
||||||
@ -457,17 +457,17 @@ PResult<Component> ComdelParser::parseComponent()
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Display := "@display {" + (DISPLAY_ITEM)* + "}"
|
* DisplayNode := "@display {" + (DISPLAY_ITEM)* + "}"
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Display> ComdelParser::parseDisplay() {
|
PResult<DisplayNode> ComdelParser::parseDisplay() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_DISPLAY);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_DISPLAY);
|
||||||
Display display;
|
DisplayNode display;
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
||||||
while(!check(TokenType::RBRACE)) {
|
while(!check(TokenType::RBRACE)) {
|
||||||
PResult<DisplayItem> item;
|
PResult<DisplayItemNode> item;
|
||||||
item = parseDisplayItem();
|
item = parseDisplayItem();
|
||||||
RETURN_IF_ERR(item);
|
RETURN_IF_ERR(item);
|
||||||
display.items.push_back(*item);
|
display.items.push_back(*item);
|
||||||
@ -478,12 +478,12 @@ PResult<Display> ComdelParser::parseDisplay() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* DisplayItem := "TYPE {(KEY + ":" + VALUE + ";")*}
|
* DisplayItemNode := "TYPE {(KEY + ":" + VALUE + ";")*}
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<DisplayItem> ComdelParser::parseDisplayItem() {
|
PResult<DisplayItemNode> ComdelParser::parseDisplayItem() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
DisplayItem displayItem;
|
DisplayItemNode displayItem;
|
||||||
ASSIGN_OR_RETURN_IF_ERR(displayItem.type, parseIdentifier());
|
ASSIGN_OR_RETURN_IF_ERR(displayItem.type, parseIdentifier());
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
||||||
@ -500,12 +500,12 @@ PResult<DisplayItem> ComdelParser::parseDisplayItem() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Bus := "@bus " + NAME + TYPE + "{" + POPUP + "}"
|
* BusNode := "@bus " + NAME + TYPE + "{" + POPUP + "}"
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Bus> ComdelParser::parseBus() {
|
PResult<BusNode> ComdelParser::parseBus() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
Bus bus;
|
BusNode bus;
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_BUS);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_BUS);
|
||||||
|
|
||||||
@ -514,9 +514,9 @@ PResult<Bus> ComdelParser::parseBus() {
|
|||||||
if(check(TokenType::IDENTIFIER)) {
|
if(check(TokenType::IDENTIFIER)) {
|
||||||
auto tokenType = parseIdentifier();
|
auto tokenType = parseIdentifier();
|
||||||
if(tokenType.value().value == "automatic") {
|
if(tokenType.value().value == "automatic") {
|
||||||
bus.type = Bus::AUTOMATIC;
|
bus.type = BusNode::AUTOMATIC;
|
||||||
} else if(tokenType.value().value == "regular") {
|
} else if(tokenType.value().value == "regular") {
|
||||||
bus.type = Bus::REGULAR;
|
bus.type = BusNode::REGULAR;
|
||||||
} else {
|
} else {
|
||||||
return PError(SourceError{current().span, "expected 'automatic' or 'regular'"});
|
return PError(SourceError{current().span, "expected 'automatic' or 'regular'"});
|
||||||
}
|
}
|
||||||
@ -558,12 +558,12 @@ PResult<Bus> ComdelParser::parseBus() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Wire := NAME(<SIZE>){0,1} TYPE)*
|
* WireNode := NAME(<SIZE>){0,1} TYPE)*
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Wire> ComdelParser::parseWire() {
|
PResult<WireNode> ComdelParser::parseWire() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
Wire wire;
|
WireNode wire;
|
||||||
|
|
||||||
ASSIGN_OR_RETURN_IF_ERR(wire.name, parseIdentifier());
|
ASSIGN_OR_RETURN_IF_ERR(wire.name, parseIdentifier());
|
||||||
|
|
||||||
@ -576,20 +576,20 @@ PResult<Wire> ComdelParser::parseWire() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default
|
// default
|
||||||
wire.type = Wire::WIRE;
|
wire.type = WireNode::WIRE;
|
||||||
|
|
||||||
if(check(TokenType::WIRE_DEFAULT)) {
|
if(check(TokenType::WIRE_DEFAULT)) {
|
||||||
bump();
|
bump();
|
||||||
wire.type = Wire::WIRE;
|
wire.type = WireNode::WIRE;
|
||||||
} else if(check(TokenType::WIRE_AND)) {
|
} else if(check(TokenType::WIRE_AND)) {
|
||||||
bump();
|
bump();
|
||||||
wire.type = Wire::WIRED_AND;
|
wire.type = WireNode::WIRED_AND;
|
||||||
} else if(check(TokenType::WIRE_OR)) {
|
} else if(check(TokenType::WIRE_OR)) {
|
||||||
bump();
|
bump();
|
||||||
wire.type = Wire::WIRED_OR;
|
wire.type = WireNode::WIRED_OR;
|
||||||
} else if(check(TokenType::R_WIRE)) {
|
} else if(check(TokenType::R_WIRE)) {
|
||||||
bump();
|
bump();
|
||||||
wire.type = Wire::R_WIRE;
|
wire.type = WireNode::R_WIRE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return spanner(wire);
|
return spanner(wire);
|
||||||
@ -598,30 +598,30 @@ PResult<Wire> ComdelParser::parseWire() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Pin := "@pin" NAME TYPE "{"
|
* PinNode := "@pin" NAME TYPE "{"
|
||||||
"@tooltip" MESSAGE
|
"@tooltip" MESSAGE
|
||||||
"@connection" TYPE "(" MESSAGE ")"
|
"@connection" TYPE "(" MESSAGE ")"
|
||||||
Display
|
DisplayNode
|
||||||
}
|
}
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Pin> ComdelParser::parsePin() {
|
PResult<PinNode> ComdelParser::parsePin() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_PIN);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_PIN);
|
||||||
Pin pin{};
|
PinNode pin{};
|
||||||
|
|
||||||
ASSIGN_OR_RETURN_IF_ERR(pin.name, parseIdentifier());
|
ASSIGN_OR_RETURN_IF_ERR(pin.name, parseIdentifier());
|
||||||
|
|
||||||
if(check(TokenType::PIN_IN)) {
|
if(check(TokenType::PIN_IN)) {
|
||||||
bump();
|
bump();
|
||||||
pin.type = Pin::IN;
|
pin.type = PinNode::IN;
|
||||||
} else if(check(TokenType::PIN_OUT)) {
|
} else if(check(TokenType::PIN_OUT)) {
|
||||||
bump();
|
bump();
|
||||||
pin.type = Pin::OUT;
|
pin.type = PinNode::OUT;
|
||||||
} else if(check(TokenType::PIN_IN_OUT)) {
|
} else if(check(TokenType::PIN_IN_OUT)) {
|
||||||
bump();
|
bump();
|
||||||
pin.type = Pin::IN_OUT;
|
pin.type = PinNode::IN_OUT;
|
||||||
} else {
|
} else {
|
||||||
return unexpected();
|
return unexpected();
|
||||||
}
|
}
|
||||||
@ -649,21 +649,21 @@ PResult<Pin> ComdelParser::parsePin() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* PinConnection := "@connection " + ("check_only" | "automatically") + "(" + MESSAGE + ")"
|
* PinConnectionNode := "@connection " + ("check_only" | "automatically") + "(" + MESSAGE + ")"
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<PinConnection> ComdelParser::parsePinConnection() {
|
PResult<PinConnectionNode> ComdelParser::parsePinConnection() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
PinConnection connection{};
|
PinConnectionNode connection{};
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);
|
||||||
|
|
||||||
if(check(TokenType::IDENTIFIER)) {
|
if(check(TokenType::IDENTIFIER)) {
|
||||||
auto type = parseIdentifier();
|
auto type = parseIdentifier();
|
||||||
if(type.value().value == "check_only") {
|
if(type.value().value == "check_only") {
|
||||||
connection.type = PinConnection::CHECK_ONLY;
|
connection.type = PinConnectionNode::CHECK_ONLY;
|
||||||
} else if(type.value().value == "automatically") {
|
} else if(type.value().value == "automatically") {
|
||||||
connection.type = PinConnection::AUTOMATICALLY;
|
connection.type = PinConnectionNode::AUTOMATICALLY;
|
||||||
} else {
|
} else {
|
||||||
return PError(SourceError{current().span, "expected identifiers 'check_only' or 'automatically'"});
|
return PError(SourceError{current().span, "expected identifiers 'check_only' or 'automatically'"});
|
||||||
}
|
}
|
||||||
@ -681,12 +681,12 @@ PResult<PinConnection> ComdelParser::parsePinConnection() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Attribute := "@attribute " + NAME + TYPE ("default" + VALUE){0,1} ("{" POPUP "}"){0,1}
|
* AttributeNode := "@attribute " + NAME + TYPE ("default" + VALUE){0,1} ("{" POPUP "}"){0,1}
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Attribute> ComdelParser::parseAttribute() {
|
PResult<AttributeNode> ComdelParser::parseAttribute() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
Attribute attribute;
|
AttributeNode attribute;
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_ATTRIBUTE);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_ATTRIBUTE);
|
||||||
|
|
||||||
@ -839,12 +839,12 @@ PResult<Popup> ComdelParser::parsePopup() {
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Connection := "@connection (" + COMPONENT + "." + PIN + "," + BUS) {" + CONNECTION + "}"
|
* ConnectionNode := "@connection (" + COMPONENT + "." + PIN + "," + BUS) {" + CONNECTION + "}"
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
PResult<Connection> ComdelParser::parseConnection() {
|
PResult<ConnectionNode> ComdelParser::parseConnection() {
|
||||||
auto spanner = getSpanner();
|
auto spanner = getSpanner();
|
||||||
Connection connection;
|
ConnectionNode connection;
|
||||||
|
|
||||||
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);
|
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);
|
||||||
|
|
||||||
|
@ -4,13 +4,12 @@
|
|||||||
#include "sourceerror.h"
|
#include "sourceerror.h"
|
||||||
#include "presult.h"
|
#include "presult.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include "astnode.h"
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <domain/library/library.h>
|
|
||||||
|
|
||||||
/// Records the current span and can later be called on
|
/// Records the current span and can later be called on
|
||||||
/// an ast node to apply the entire span to that node
|
/// an ast node to apply the entire span to that node
|
||||||
///
|
///
|
||||||
@ -71,24 +70,24 @@ private:
|
|||||||
PResult<PropertyNode> parseProperty(std::optional<TokenType> valueType);
|
PResult<PropertyNode> parseProperty(std::optional<TokenType> valueType);
|
||||||
PResult<EnumerationNode> parseEnumeration();
|
PResult<EnumerationNode> parseEnumeration();
|
||||||
|
|
||||||
PResult<Component> parseComponent();
|
PResult<ComponentNode> parseComponent();
|
||||||
PResult<AddressSpace> parseAddress();
|
PResult<AddressSpace> parseAddress();
|
||||||
PResult<Pin> parsePin();
|
PResult<PinNode> parsePin();
|
||||||
PResult<Display> parseDisplay();
|
PResult<DisplayNode> parseDisplay();
|
||||||
PResult<PinConnection> parsePinConnection();
|
PResult<PinConnectionNode> parsePinConnection();
|
||||||
PResult<Attribute> parseAttribute();
|
PResult<AttributeNode> parseAttribute();
|
||||||
PResult<Popup> parsePopup();
|
PResult<Popup> parsePopup();
|
||||||
PResult<Rule> parseRule();
|
PResult<Rule> parseRule();
|
||||||
PResult<Bus> parseBus();
|
PResult<BusNode> parseBus();
|
||||||
PResult<Wire> parseWire();
|
PResult<WireNode> parseWire();
|
||||||
PResult<Connection> parseConnection();
|
PResult<ConnectionNode> parseConnection();
|
||||||
PResult<DisplayItem> parseDisplayItem();
|
PResult<DisplayItemNode> parseDisplayItem();
|
||||||
PResult<IfStmt> parseIfStatement();
|
PResult<IfStmt> parseIfStatement();
|
||||||
PResult<Value> parseValue();
|
PResult<Value> parseValue();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ComdelParser(std::vector<Token> tokens);
|
ComdelParser(std::vector<Token> tokens);
|
||||||
std::optional<Library> parse();
|
std::optional<LibraryNode> parse();
|
||||||
const std::vector<SourceError>& getErrors();
|
const std::vector<SourceError>& getErrors();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::optional<Library> loadLibraryFromFile(ParseContext * parseContext,
|
std::optional<LibraryNode> loadLibraryFromFile(ParseContext * parseContext,
|
||||||
const char* name,
|
const char* name,
|
||||||
std::ostream& stream)
|
std::ostream& stream)
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#ifndef PARSERUTIL_H
|
#ifndef PARSERUTIL_H
|
||||||
#define PARSERUTIL_H
|
#define PARSERUTIL_H
|
||||||
|
|
||||||
|
#include "astnode.h"
|
||||||
#include "parsecontext.h"
|
#include "parsecontext.h"
|
||||||
|
|
||||||
#include <domain/library/library.h>
|
std::optional<LibraryNode> loadLibraryFromFile(ParseContext * parseContext,
|
||||||
|
|
||||||
std::optional<Library> loadLibraryFromFile(ParseContext * parseContext,
|
|
||||||
const char* name,
|
const char* name,
|
||||||
std::ostream& stream);
|
std::ostream& stream);
|
||||||
|
|
||||||
|
@ -113,17 +113,17 @@ TokenTables::TokenTables() {
|
|||||||
add( TokenType::BOOL_TYPE, "bool", TOKENIZABLE),
|
add( TokenType::BOOL_TYPE, "bool", TOKENIZABLE),
|
||||||
add( TokenType::WIRE_TYPE, "wire", TOKENIZABLE),
|
add( TokenType::WIRE_TYPE, "wire", TOKENIZABLE),
|
||||||
|
|
||||||
// Wire types
|
// WireNode types
|
||||||
add( TokenType::WIRE_DEFAULT, "normal_wire", TOKENIZABLE),
|
add( TokenType::WIRE_DEFAULT, "normal_wire", TOKENIZABLE),
|
||||||
add( TokenType::WIRE_AND, "wired_and", TOKENIZABLE),
|
add( TokenType::WIRE_AND, "wired_and", TOKENIZABLE),
|
||||||
add( TokenType::WIRE_OR, "wired_or", TOKENIZABLE),
|
add( TokenType::WIRE_OR, "wired_or", TOKENIZABLE),
|
||||||
add( TokenType::R_WIRE, "r_wire", TOKENIZABLE),
|
add( TokenType::R_WIRE, "r_wire", TOKENIZABLE),
|
||||||
|
|
||||||
// Component types
|
// ComponentNode types
|
||||||
add( TokenType::CT_MEMORY, "memory", TOKENIZABLE),
|
add( TokenType::CT_MEMORY, "memory", TOKENIZABLE),
|
||||||
add( TokenType::CT_PROCESSOR, "processor", TOKENIZABLE),
|
add( TokenType::CT_PROCESSOR, "processor", TOKENIZABLE),
|
||||||
|
|
||||||
// Pin type
|
// PinNode type
|
||||||
add( TokenType::PIN_IN, "in", TOKENIZABLE),
|
add( TokenType::PIN_IN, "in", TOKENIZABLE),
|
||||||
add( TokenType::PIN_OUT, "out", TOKENIZABLE),
|
add( TokenType::PIN_OUT, "out", TOKENIZABLE),
|
||||||
add( TokenType::PIN_IN_OUT, "inOut", TOKENIZABLE),
|
add( TokenType::PIN_IN_OUT, "inOut", TOKENIZABLE),
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#include "display.h"
|
|
||||||
|
|
||||||
Display::Display()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#ifndef DOMAIN_DISPLAY_DISPLAY_H
|
|
||||||
#define DOMAIN_DISPLAY_DISPLAY_H
|
|
||||||
|
|
||||||
#include "displayitem.h"
|
|
||||||
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Display: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Display();
|
|
||||||
|
|
||||||
std::vector<DisplayItem> items;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_DISPLAY_DISPLAY_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "displayitem.h"
|
|
||||||
|
|
||||||
DisplayItem::DisplayItem()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#ifndef DISPLAYITEM_H
|
|
||||||
#define DISPLAYITEM_H
|
|
||||||
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
#include <vector>
|
|
||||||
#include "../library/value.h"
|
|
||||||
|
|
||||||
|
|
||||||
class DisplayItem: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IdentifierNode type;
|
|
||||||
std::vector<PropertyNode> values;
|
|
||||||
DisplayItem();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DISPLAYITEM_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "addressspace.h"
|
|
||||||
|
|
||||||
AddressSpace::AddressSpace()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
#ifndef ADDRESSSPACE_H
|
|
||||||
#define ADDRESSSPACE_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
|
|
||||||
class AddressSpace: public AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IdentifierNode name;
|
|
||||||
NumberNode start;
|
|
||||||
NumberNode end;
|
|
||||||
|
|
||||||
AddressSpace();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // ADDRESSSPACE_H
|
|
@ -1,5 +0,0 @@
|
|||||||
#include "attribute.h"
|
|
||||||
|
|
||||||
Attribute::Attribute()
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_ATTRIBUTE_H
|
|
||||||
#define DOMAIN_LIBRARY_ATTRIBUTE_H
|
|
||||||
|
|
||||||
#include "value.h"
|
|
||||||
#include "popup.h"
|
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
class Attribute: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Value::ValueType type;
|
|
||||||
IdentifierNode name;
|
|
||||||
std::optional<Value> defaultValue;
|
|
||||||
std::optional<Popup> popup;
|
|
||||||
|
|
||||||
Attribute();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_ATTRIBUTE_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "bus.h"
|
|
||||||
|
|
||||||
Bus::Bus()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_BUS_H
|
|
||||||
#define DOMAIN_LIBRARY_BUS_H
|
|
||||||
|
|
||||||
#include "wire.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <domain/display/display.h>
|
|
||||||
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
|
|
||||||
|
|
||||||
class Bus: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum BusType {
|
|
||||||
AUTOMATIC,
|
|
||||||
REGULAR
|
|
||||||
};
|
|
||||||
|
|
||||||
BusType type;
|
|
||||||
IdentifierNode name;
|
|
||||||
StringNode tooltip;
|
|
||||||
CountNode count;
|
|
||||||
Display display;
|
|
||||||
|
|
||||||
std::vector<Wire> wires;
|
|
||||||
|
|
||||||
Bus();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_BUS_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "component.h"
|
|
||||||
|
|
||||||
Component::Component()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#ifndef COMPONENT_H
|
|
||||||
#define COMPONENT_H
|
|
||||||
|
|
||||||
#include "rule.h"
|
|
||||||
#include "pin.h"
|
|
||||||
#include "attribute.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <domain/display/display.h>
|
|
||||||
|
|
||||||
|
|
||||||
class Component: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum ComponentType {
|
|
||||||
OTHER,
|
|
||||||
PROCESSOR,
|
|
||||||
MEMORY
|
|
||||||
};
|
|
||||||
|
|
||||||
IdentifierNode name;
|
|
||||||
StringNode tooltip;
|
|
||||||
StringNode source;
|
|
||||||
ComponentType type;
|
|
||||||
std::vector<Rule> rules;
|
|
||||||
StringNode instanceName;
|
|
||||||
CountNode count;
|
|
||||||
Display display;
|
|
||||||
std::vector<Pin> pin;
|
|
||||||
std::vector<Attribute> attributes;
|
|
||||||
|
|
||||||
Component();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // COMPONENT_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "connection.h"
|
|
||||||
|
|
||||||
Connection::Connection()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_CONNECTION_H
|
|
||||||
#define DOMAIN_LIBRARY_CONNECTION_H
|
|
||||||
|
|
||||||
#include "attribute.h"
|
|
||||||
#include "bus.h"
|
|
||||||
#include "component.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Connection: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IdentifierNode component;
|
|
||||||
IdentifierNode pin;
|
|
||||||
IdentifierNode bus;
|
|
||||||
std::vector<Attribute> attributes;
|
|
||||||
std::vector<IdentifierNode> wires;
|
|
||||||
|
|
||||||
Connection();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_CONNECTION_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "library.h"
|
|
||||||
|
|
||||||
Library::Library()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
#ifndef LIBRARY_H
|
|
||||||
#define LIBRARY_H
|
|
||||||
|
|
||||||
#include "addressspace.h"
|
|
||||||
#include "bus.h"
|
|
||||||
#include "component.h"
|
|
||||||
#include "connection.h"
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Library: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
StringNode name;
|
|
||||||
StringNode libraryInfo;
|
|
||||||
StringNode header;
|
|
||||||
StringNode componentDirectory;
|
|
||||||
|
|
||||||
std::vector<AddressSpace> addressSpaces;
|
|
||||||
|
|
||||||
std::vector<Component> components;
|
|
||||||
std::vector<Bus> buses;
|
|
||||||
std::vector<Connection> connections;
|
|
||||||
|
|
||||||
std::vector<PropertyNode> messages;
|
|
||||||
|
|
||||||
Library();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // LIBRARY_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "pin.h"
|
|
||||||
|
|
||||||
Pin::Pin()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_PIN_H
|
|
||||||
#define DOMAIN_LIBRARY_PIN_H
|
|
||||||
|
|
||||||
#include <domain/display/display.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
|
|
||||||
|
|
||||||
class PinConnection: AstNode {
|
|
||||||
public:
|
|
||||||
enum ConnectionType {
|
|
||||||
CHECK_ONLY,
|
|
||||||
AUTOMATICALLY
|
|
||||||
};
|
|
||||||
|
|
||||||
StringNode message;
|
|
||||||
ConnectionType type;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Pin: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum PinType {
|
|
||||||
IN_OUT,
|
|
||||||
IN,
|
|
||||||
OUT
|
|
||||||
};
|
|
||||||
|
|
||||||
IdentifierNode name;
|
|
||||||
PinType type;
|
|
||||||
StringNode tooltip;
|
|
||||||
|
|
||||||
PinConnection connection;
|
|
||||||
|
|
||||||
Display display;
|
|
||||||
|
|
||||||
Pin();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_PIN_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "popup.h"
|
|
||||||
|
|
||||||
Popup::Popup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_POPUP_H
|
|
||||||
#define DOMAIN_LIBRARY_POPUP_H
|
|
||||||
|
|
||||||
#include "rule.h"
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
class EnumerationNode: AstNode {
|
|
||||||
public:
|
|
||||||
StringNode key;
|
|
||||||
Value value;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Popup: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum PopupType {
|
|
||||||
AUTOMATIC,
|
|
||||||
ON_DEMAND
|
|
||||||
};
|
|
||||||
|
|
||||||
PopupType type;
|
|
||||||
StringNode title;
|
|
||||||
StringNode text;
|
|
||||||
|
|
||||||
bool enumerated;
|
|
||||||
std::vector<EnumerationNode> enumeration;
|
|
||||||
|
|
||||||
std::vector<Rule> rules;
|
|
||||||
|
|
||||||
Popup();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_POPUP_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "rule.h"
|
|
||||||
|
|
||||||
Rule::Rule()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_RULE_H
|
|
||||||
#define DOMAIN_LIBRARY_RULE_H
|
|
||||||
|
|
||||||
#include "value.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Action;
|
|
||||||
class Condition;
|
|
||||||
class IfStmt;
|
|
||||||
|
|
||||||
class Rule: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::vector<IfStmt> statements;
|
|
||||||
Rule();
|
|
||||||
};
|
|
||||||
|
|
||||||
class Action: AstNode {
|
|
||||||
public:
|
|
||||||
enum ActionType {
|
|
||||||
ERROR,
|
|
||||||
WARNING
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionType type;
|
|
||||||
StringNode message;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Condition {
|
|
||||||
public:
|
|
||||||
bool negated;
|
|
||||||
IdentifierNode functionName;
|
|
||||||
std::vector<Value> params;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IfStmt: AstNode {
|
|
||||||
public:
|
|
||||||
Condition condition;
|
|
||||||
Action action;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_RULE_H
|
|
@ -1,5 +0,0 @@
|
|||||||
#include "value.h"
|
|
||||||
|
|
||||||
Value::Value()
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_VALUE_H
|
|
||||||
#define DOMAIN_LIBRARY_VALUE_H
|
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
|
|
||||||
class Value: AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum ValueType {
|
|
||||||
INT,
|
|
||||||
STRING,
|
|
||||||
BOOL,
|
|
||||||
IDENTIFIER
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
ValueType type;
|
|
||||||
std::optional<long long> intValue;
|
|
||||||
std::optional<std::string> stringValue;
|
|
||||||
std::optional<bool> boolValue;
|
|
||||||
std::optional<std::string> identifierValue;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Value();
|
|
||||||
|
|
||||||
ValueType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
long long asInt() {
|
|
||||||
if(is(INT)) {
|
|
||||||
return intValue.value();
|
|
||||||
}
|
|
||||||
throw "cannot convert type to int";
|
|
||||||
}
|
|
||||||
std::string asString() {
|
|
||||||
if(is(STRING)) {
|
|
||||||
return stringValue.value();
|
|
||||||
}
|
|
||||||
throw "cannot convert type to string";
|
|
||||||
}
|
|
||||||
std::string asIdentifier() {
|
|
||||||
if(is(IDENTIFIER)) {
|
|
||||||
return identifierValue.value();
|
|
||||||
}
|
|
||||||
throw "cannot convert type to identifier";
|
|
||||||
}
|
|
||||||
bool asBool() {
|
|
||||||
if(is(BOOL)) {
|
|
||||||
return boolValue.value();
|
|
||||||
}
|
|
||||||
throw "cannot convert type to bool";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is(ValueType type) {
|
|
||||||
return this->type == type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Value ofBool(bool _value) {
|
|
||||||
Value value;
|
|
||||||
value.type = BOOL;
|
|
||||||
value.boolValue = std::optional<bool>(_value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Value ofInt(long long _value) {
|
|
||||||
Value value;
|
|
||||||
value.type = INT;
|
|
||||||
value.intValue = std::optional<long long>(_value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Value ofString(std::string _value) {
|
|
||||||
Value value;
|
|
||||||
value.type = STRING;
|
|
||||||
value.stringValue = std::optional<std::string>(_value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Value ofIdentifier(std::string _value) {
|
|
||||||
Value value;
|
|
||||||
value.type = IDENTIFIER;
|
|
||||||
value.identifierValue = std::optional<std::string>(_value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class PropertyNode: public AstNode {
|
|
||||||
public:
|
|
||||||
IdentifierNode key;
|
|
||||||
Value value;
|
|
||||||
|
|
||||||
PropertyNode() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_VALUE_H
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "wire.h"
|
|
||||||
|
|
||||||
Wire::Wire()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
#ifndef DOMAIN_LIBRARY_WIRE_H
|
|
||||||
#define DOMAIN_LIBRARY_WIRE_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <comdel/parser/astnode.h>
|
|
||||||
|
|
||||||
|
|
||||||
class Wire: public AstNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum WireType {
|
|
||||||
WIRE,
|
|
||||||
WIRED_AND,
|
|
||||||
WIRED_OR,
|
|
||||||
R_WIRE
|
|
||||||
};
|
|
||||||
WireType type;
|
|
||||||
IdentifierNode name;
|
|
||||||
NumberNode size;
|
|
||||||
/*
|
|
||||||
bool isTerminatedWith;
|
|
||||||
long terminatedWith;
|
|
||||||
|
|
||||||
bool isIfUntrminated;
|
|
||||||
long ifUnterminated;
|
|
||||||
*/
|
|
||||||
Wire();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DOMAIN_LIBRARY_WIRE_H
|
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef DOMAIN_SCHEMA_ATTRIBUTE_H
|
#ifndef DOMAIN_SCHEMA_ATTRIBUTE_H
|
||||||
#define DOMAIN_SCHEMA_ATTRIBUTE_H
|
#define DOMAIN_SCHEMA_ATTRIBUTE_H
|
||||||
|
|
||||||
#include <domain/library/value.h>
|
#include <comdel/parser/astnode.h>
|
||||||
|
|
||||||
class InstanceAttribute: AstNode
|
class InstanceAttribute: AstNode
|
||||||
{
|
{
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
#define DOMAIN_SCHEMA_WIREINSTANCE_H
|
#define DOMAIN_SCHEMA_WIREINSTANCE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <domain/display/display.h>
|
|
||||||
#include <comdel/parser/astnode.h>
|
#include <comdel/parser/astnode.h>
|
||||||
|
|
||||||
class WireInstance: AstNode
|
class WireInstance: AstNode
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::pair<int, int> position;
|
std::pair<int, int> position;
|
||||||
Display display;
|
DisplayNode display;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WireInstance();
|
WireInstance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user