This commit is contained in:
Borna Rajkovic 2022-03-29 23:49:32 +02:00
parent 4c921759ef
commit 18d84727ab
35 changed files with 362 additions and 636 deletions

View File

@ -18,19 +18,6 @@ SOURCES += \
comdel/parser/sourceerror.cpp \
comdel/parser/token.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/instance.cpp \
domain/schema/instanceattribute.cpp \
@ -52,19 +39,6 @@ HEADERS += \
comdel/parser/sourceerror.h \
comdel/parser/token.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/instance.h \
domain/schema/instanceattribute.h \

View File

@ -2,6 +2,8 @@
#define ASTNODE_H
#include "token.h"
#include <optional>
#include <vector>
/**
* AST base class, all AST node classes extand this class. Class contains basic
@ -26,26 +28,24 @@ public:
};
class StringNode: public AstNode {
public:
struct StringNode: public AstNode
{
std::string value;
};
class IdentifierNode: public AstNode {
public:
struct IdentifierNode: public AstNode
{
std::string value;
};
class NumberNode: public AstNode {
public:
struct NumberNode: public AstNode {
long long int value;
NumberNode(std::string expression);
NumberNode(): value(0) {}
};
class CountNode: public AstNode {
public:
struct CountNode: public AstNode
{
NumberNode first;
NumberNode second;
@ -53,4 +53,292 @@ public:
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

View File

@ -207,11 +207,11 @@ Spanner ComdelParser::getSpanner()
*
****************************************************************************/
std::optional<Library> ComdelParser::parse()
std::optional<LibraryNode> ComdelParser::parse()
{
auto spanner = getSpanner();
Library library{};
LibraryNode library{};
while ( ! check(TokenType::END_OF_FILE) ) {
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();
Component component{};
ComponentNode component{};
RETURN_IF_NOT_TOKEN(TokenType::KW_COMPONENT);
@ -413,12 +413,12 @@ PResult<Component> ComdelParser::parseComponent()
if(check(TokenType::CT_PROCESSOR)) {
bump();
component.type = Component::PROCESSOR;
component.type = ComponentNode::PROCESSOR;
} else if(check(TokenType::CT_MEMORY)) {
bump();
component.type = Component::MEMORY;
component.type = ComponentNode::MEMORY;
} else {
component.type = Component::OTHER;
component.type = ComponentNode::OTHER;
}
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();
RETURN_IF_NOT_TOKEN(TokenType::KW_DISPLAY);
Display display;
DisplayNode display;
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
while(!check(TokenType::RBRACE)) {
PResult<DisplayItem> item;
PResult<DisplayItemNode> item;
item = parseDisplayItem();
RETURN_IF_ERR(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();
DisplayItem displayItem;
DisplayItemNode displayItem;
ASSIGN_OR_RETURN_IF_ERR(displayItem.type, parseIdentifier());
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();
Bus bus;
BusNode bus;
RETURN_IF_NOT_TOKEN(TokenType::KW_BUS);
@ -514,9 +514,9 @@ PResult<Bus> ComdelParser::parseBus() {
if(check(TokenType::IDENTIFIER)) {
auto tokenType = parseIdentifier();
if(tokenType.value().value == "automatic") {
bus.type = Bus::AUTOMATIC;
bus.type = BusNode::AUTOMATIC;
} else if(tokenType.value().value == "regular") {
bus.type = Bus::REGULAR;
bus.type = BusNode::REGULAR;
} else {
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();
Wire wire;
WireNode wire;
ASSIGN_OR_RETURN_IF_ERR(wire.name, parseIdentifier());
@ -576,20 +576,20 @@ PResult<Wire> ComdelParser::parseWire() {
}
// default
wire.type = Wire::WIRE;
wire.type = WireNode::WIRE;
if(check(TokenType::WIRE_DEFAULT)) {
bump();
wire.type = Wire::WIRE;
wire.type = WireNode::WIRE;
} else if(check(TokenType::WIRE_AND)) {
bump();
wire.type = Wire::WIRED_AND;
wire.type = WireNode::WIRED_AND;
} else if(check(TokenType::WIRE_OR)) {
bump();
wire.type = Wire::WIRED_OR;
wire.type = WireNode::WIRED_OR;
} else if(check(TokenType::R_WIRE)) {
bump();
wire.type = Wire::R_WIRE;
wire.type = WireNode::R_WIRE;
}
return spanner(wire);
@ -598,30 +598,30 @@ PResult<Wire> ComdelParser::parseWire() {
/****************************************************************************
*
* Pin := "@pin" NAME TYPE "{"
* PinNode := "@pin" NAME TYPE "{"
"@tooltip" MESSAGE
"@connection" TYPE "(" MESSAGE ")"
Display
DisplayNode
}
*
****************************************************************************/
PResult<Pin> ComdelParser::parsePin() {
PResult<PinNode> ComdelParser::parsePin() {
auto spanner = getSpanner();
RETURN_IF_NOT_TOKEN(TokenType::KW_PIN);
Pin pin{};
PinNode pin{};
ASSIGN_OR_RETURN_IF_ERR(pin.name, parseIdentifier());
if(check(TokenType::PIN_IN)) {
bump();
pin.type = Pin::IN;
pin.type = PinNode::IN;
} else if(check(TokenType::PIN_OUT)) {
bump();
pin.type = Pin::OUT;
pin.type = PinNode::OUT;
} else if(check(TokenType::PIN_IN_OUT)) {
bump();
pin.type = Pin::IN_OUT;
pin.type = PinNode::IN_OUT;
} else {
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();
PinConnection connection{};
PinConnectionNode connection{};
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);
if(check(TokenType::IDENTIFIER)) {
auto type = parseIdentifier();
if(type.value().value == "check_only") {
connection.type = PinConnection::CHECK_ONLY;
connection.type = PinConnectionNode::CHECK_ONLY;
} else if(type.value().value == "automatically") {
connection.type = PinConnection::AUTOMATICALLY;
connection.type = PinConnectionNode::AUTOMATICALLY;
} else {
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();
Attribute attribute;
AttributeNode 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();
Connection connection;
ConnectionNode connection;
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);

View File

@ -4,13 +4,12 @@
#include "sourceerror.h"
#include "presult.h"
#include "token.h"
#include "astnode.h"
#include <optional>
#include <set>
#include <vector>
#include <domain/library/library.h>
/// Records the current span and can later be called on
/// an ast node to apply the entire span to that node
///
@ -71,24 +70,24 @@ private:
PResult<PropertyNode> parseProperty(std::optional<TokenType> valueType);
PResult<EnumerationNode> parseEnumeration();
PResult<Component> parseComponent();
PResult<ComponentNode> parseComponent();
PResult<AddressSpace> parseAddress();
PResult<Pin> parsePin();
PResult<Display> parseDisplay();
PResult<PinConnection> parsePinConnection();
PResult<Attribute> parseAttribute();
PResult<PinNode> parsePin();
PResult<DisplayNode> parseDisplay();
PResult<PinConnectionNode> parsePinConnection();
PResult<AttributeNode> parseAttribute();
PResult<Popup> parsePopup();
PResult<Rule> parseRule();
PResult<Bus> parseBus();
PResult<Wire> parseWire();
PResult<Connection> parseConnection();
PResult<DisplayItem> parseDisplayItem();
PResult<BusNode> parseBus();
PResult<WireNode> parseWire();
PResult<ConnectionNode> parseConnection();
PResult<DisplayItemNode> parseDisplayItem();
PResult<IfStmt> parseIfStatement();
PResult<Value> parseValue();
public:
ComdelParser(std::vector<Token> tokens);
std::optional<Library> parse();
std::optional<LibraryNode> parse();
const std::vector<SourceError>& getErrors();
};

View File

@ -6,7 +6,7 @@
#include <fstream>
#include <string>
std::optional<Library> loadLibraryFromFile(ParseContext * parseContext,
std::optional<LibraryNode> loadLibraryFromFile(ParseContext * parseContext,
const char* name,
std::ostream& stream)
{

View File

@ -1,11 +1,10 @@
#ifndef PARSERUTIL_H
#define PARSERUTIL_H
#include "astnode.h"
#include "parsecontext.h"
#include <domain/library/library.h>
std::optional<Library> loadLibraryFromFile(ParseContext * parseContext,
std::optional<LibraryNode> loadLibraryFromFile(ParseContext * parseContext,
const char* name,
std::ostream& stream);

View File

@ -113,17 +113,17 @@ TokenTables::TokenTables() {
add( TokenType::BOOL_TYPE, "bool", TOKENIZABLE),
add( TokenType::WIRE_TYPE, "wire", TOKENIZABLE),
// Wire types
// WireNode types
add( TokenType::WIRE_DEFAULT, "normal_wire", TOKENIZABLE),
add( TokenType::WIRE_AND, "wired_and", TOKENIZABLE),
add( TokenType::WIRE_OR, "wired_or", TOKENIZABLE),
add( TokenType::R_WIRE, "r_wire", TOKENIZABLE),
// Component types
// ComponentNode types
add( TokenType::CT_MEMORY, "memory", TOKENIZABLE),
add( TokenType::CT_PROCESSOR, "processor", TOKENIZABLE),
// Pin type
// PinNode type
add( TokenType::PIN_IN, "in", TOKENIZABLE),
add( TokenType::PIN_OUT, "out", TOKENIZABLE),
add( TokenType::PIN_IN_OUT, "inOut", TOKENIZABLE),

View File

@ -1,6 +0,0 @@
#include "display.h"
Display::Display()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "displayitem.h"
DisplayItem::DisplayItem()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "addressspace.h"
AddressSpace::AddressSpace()
{
}

View File

@ -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

View File

@ -1,5 +0,0 @@
#include "attribute.h"
Attribute::Attribute()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "bus.h"
Bus::Bus()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "component.h"
Component::Component()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "connection.h"
Connection::Connection()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "library.h"
Library::Library()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "pin.h"
Pin::Pin()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "popup.h"
Popup::Popup()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "rule.h"
Rule::Rule()
{
}

View File

@ -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

View File

@ -1,5 +0,0 @@
#include "value.h"
Value::Value()
{
}

View File

@ -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

View File

@ -1,6 +0,0 @@
#include "wire.h"
Wire::Wire()
{
}

View File

@ -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

View File

@ -1,7 +1,7 @@
#ifndef DOMAIN_SCHEMA_ATTRIBUTE_H
#define DOMAIN_SCHEMA_ATTRIBUTE_H
#include <domain/library/value.h>
#include <comdel/parser/astnode.h>
class InstanceAttribute: AstNode
{

View File

@ -2,14 +2,13 @@
#define DOMAIN_SCHEMA_WIREINSTANCE_H
#include <string>
#include <domain/display/display.h>
#include <comdel/parser/astnode.h>
class WireInstance: AstNode
{
std::string name;
std::pair<int, int> position;
Display display;
DisplayNode display;
public:
WireInstance();