2022-04-08 18:17:58 +00:00
|
|
|
#ifndef AST_NODE_H
|
|
|
|
#define AST_NODE_H
|
2022-03-29 19:31:45 +00:00
|
|
|
|
|
|
|
#include "token.h"
|
2022-03-29 21:49:32 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <vector>
|
2022-03-29 19:31:45 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-08 18:17:58 +00:00
|
|
|
* AST base class, all AST node classes extend this class. Class contains basic
|
|
|
|
* information about nodes location in file.
|
2022-03-29 19:31:45 +00:00
|
|
|
*/
|
|
|
|
class AstNode {
|
|
|
|
public:
|
|
|
|
|
|
|
|
Span span;
|
|
|
|
|
|
|
|
AstNode() = default;
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
virtual ~AstNode();
|
2022-03-29 19:31:45 +00:00
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
AstNode(AstNode&&) = default;
|
2022-03-29 19:31:45 +00:00
|
|
|
AstNode& operator=(AstNode&&) = default;
|
|
|
|
AstNode(const AstNode&) = default;
|
|
|
|
AstNode& operator=(const AstNode&) = default;
|
2022-04-24 20:21:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct EnumNode: public AstNode
|
|
|
|
{
|
|
|
|
EnumNode() = default;
|
|
|
|
explicit EnumNode(T value): value(value) {}
|
2022-03-29 19:31:45 +00:00
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
T value;
|
2022-03-29 19:31:45 +00:00
|
|
|
};
|
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
struct StringNode: public AstNode
|
|
|
|
{
|
2022-03-29 19:31:45 +00:00
|
|
|
std::string value;
|
2022-04-24 20:21:45 +00:00
|
|
|
std::string asString();
|
2022-03-29 19:31:45 +00:00
|
|
|
};
|
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
struct IdentifierNode: public AstNode
|
|
|
|
{
|
2022-03-29 19:31:45 +00:00
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
struct NumberNode: public AstNode {
|
2022-03-29 19:31:45 +00:00
|
|
|
long long int value;
|
2022-04-24 20:21:45 +00:00
|
|
|
explicit NumberNode(const std::string& expression);
|
2022-03-29 19:31:45 +00:00
|
|
|
NumberNode(): value(0) {}
|
|
|
|
};
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
struct CountNode: public AstNode
|
|
|
|
{
|
2022-03-29 19:31:45 +00:00
|
|
|
NumberNode first;
|
|
|
|
NumberNode second;
|
|
|
|
|
|
|
|
CountNode(NumberNode first, NumberNode second): first(first), second(second) {}
|
2022-04-24 20:21:45 +00:00
|
|
|
CountNode() = default;
|
2022-03-29 19:31:45 +00:00
|
|
|
};
|
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
struct AddressSpaceNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
IdentifierNode name;
|
|
|
|
NumberNode start;
|
|
|
|
NumberNode end;
|
|
|
|
};
|
|
|
|
|
2022-04-08 17:13:53 +00:00
|
|
|
class ValueNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum ValueType {
|
|
|
|
INT,
|
|
|
|
STRING,
|
|
|
|
BOOL,
|
2022-03-31 21:20:41 +00:00
|
|
|
WIRE,
|
2022-04-08 20:46:47 +00:00
|
|
|
IDENTIFIER,
|
|
|
|
NIL,
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<ValueType> type;
|
2022-03-29 21:49:32 +00:00
|
|
|
std::optional<long long> intValue;
|
|
|
|
std::optional<std::string> stringValue;
|
|
|
|
std::optional<bool> boolValue;
|
|
|
|
std::optional<std::string> identifierValue;
|
|
|
|
|
|
|
|
public:
|
2022-04-24 20:21:45 +00:00
|
|
|
ValueNode() = default;;
|
2022-03-31 21:20:41 +00:00
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
ValueType getType() {
|
2022-04-24 20:21:45 +00:00
|
|
|
return type.value;
|
2022-03-31 21:20:41 +00:00
|
|
|
}
|
2022-04-24 20:21:45 +00:00
|
|
|
long long asInt();
|
|
|
|
std::string asString();
|
|
|
|
std::string asIdentifier();
|
|
|
|
bool asBool();
|
|
|
|
|
|
|
|
bool is(ValueType valueType);
|
|
|
|
|
|
|
|
static ValueNode ofBool(bool _value);
|
|
|
|
static ValueNode ofInt(long long _value);
|
|
|
|
static ValueNode ofString(std::string _value);
|
|
|
|
static ValueNode ofIdentifier(std::string _value);
|
|
|
|
static ValueNode ofNull();
|
|
|
|
static ValueNode ofWire(std::string _value);
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
struct ConditionNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
bool negated;
|
|
|
|
IdentifierNode functionName;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::vector<ValueNode> params;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
class ActionNode: public AstNode {
|
2022-03-29 21:49:32 +00:00
|
|
|
public:
|
|
|
|
enum ActionType {
|
|
|
|
ERROR,
|
|
|
|
WARNING
|
|
|
|
};
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<ActionType> type;
|
2022-03-29 21:49:32 +00:00
|
|
|
StringNode message;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct IfStatementNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
2022-03-31 21:20:41 +00:00
|
|
|
ConditionNode condition;
|
|
|
|
ActionNode action;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct RuleNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
2022-04-08 18:17:58 +00:00
|
|
|
std::vector<IfStatementNode> statements;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct EnumerationNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
StringNode key;
|
2022-03-31 21:20:41 +00:00
|
|
|
ValueNode value;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct PopupNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
enum PopupType {
|
|
|
|
AUTOMATIC,
|
|
|
|
ON_DEMAND
|
|
|
|
};
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
std::optional<EnumNode<PopupType>> type;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::optional<StringNode> title;
|
|
|
|
std::optional<StringNode> text;
|
2022-03-29 21:49:32 +00:00
|
|
|
|
|
|
|
bool enumerated;
|
|
|
|
std::vector<EnumerationNode> enumeration;
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
std::vector<RuleNode> rules;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PropertyNode: public AstNode
|
|
|
|
{
|
|
|
|
IdentifierNode key;
|
2022-03-31 21:20:41 +00:00
|
|
|
ValueNode value;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct DisplayItemNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
IdentifierNode type;
|
|
|
|
std::vector<PropertyNode> values;
|
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct DisplayNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
std::vector<DisplayItemNode> items;
|
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct PinConnectionNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
enum ConnectionType {
|
2022-05-08 12:50:56 +00:00
|
|
|
REQUIRED,
|
|
|
|
OPTIONAL
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
StringNode message;
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<ConnectionType> type;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct PinNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
enum PinType {
|
|
|
|
IN_OUT,
|
|
|
|
IN,
|
|
|
|
OUT
|
|
|
|
};
|
|
|
|
|
|
|
|
IdentifierNode name;
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<PinType> type;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::optional<StringNode> tooltip;
|
|
|
|
std::optional<PinConnectionNode> connection;
|
|
|
|
std::optional<DisplayNode> display;
|
2022-04-09 12:10:40 +00:00
|
|
|
std::optional<std::vector<ValueNode>> wires;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct WireNode: public AstNode
|
|
|
|
{
|
|
|
|
enum WireType {
|
|
|
|
WIRE,
|
|
|
|
WIRED_AND,
|
|
|
|
WIRED_OR,
|
|
|
|
R_WIRE
|
|
|
|
};
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<WireType> type;
|
2022-03-29 21:49:32 +00:00
|
|
|
IdentifierNode name;
|
|
|
|
NumberNode size;
|
|
|
|
|
2022-04-05 21:48:07 +00:00
|
|
|
bool hidden;
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
bool hasTerminateWith;
|
|
|
|
ValueNode terminateWith;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct AttributeNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
2022-03-31 21:20:41 +00:00
|
|
|
ValueNode::ValueType type;
|
2022-03-29 21:49:32 +00:00
|
|
|
IdentifierNode name;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::optional<ValueNode> defaultValue;
|
|
|
|
std::optional<PopupNode> popup;
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct ConnectionComponentNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
IdentifierNode component;
|
|
|
|
IdentifierNode pin;
|
2022-04-09 17:44:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConnectionNode: public AstNode
|
|
|
|
{
|
|
|
|
ConnectionComponentNode first;
|
|
|
|
std::optional<ConnectionComponentNode> second;
|
|
|
|
|
2022-03-29 21:49:32 +00:00
|
|
|
IdentifierNode bus;
|
|
|
|
std::vector<AttributeNode> attributes;
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
std::vector<ValueNode> firstWires;
|
|
|
|
std::optional<std::vector<ValueNode>> secondWires;
|
|
|
|
};
|
2022-03-29 21:49:32 +00:00
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct ComponentNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
enum ComponentType {
|
|
|
|
OTHER,
|
|
|
|
PROCESSOR,
|
|
|
|
MEMORY
|
|
|
|
};
|
|
|
|
|
|
|
|
IdentifierNode name;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::optional<StringNode> tooltip;
|
|
|
|
std::optional<StringNode> source;
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<ComponentType> type;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::vector<RuleNode> rules;
|
|
|
|
std::optional<StringNode> instanceName;
|
|
|
|
std::optional<CountNode> count;
|
|
|
|
std::optional<DisplayNode> display;
|
|
|
|
std::vector<PinNode> pins;
|
2022-03-29 21:49:32 +00:00
|
|
|
std::vector<AttributeNode> attributes;
|
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct BusNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
|
|
|
enum BusType {
|
|
|
|
AUTOMATIC,
|
2022-05-08 12:50:56 +00:00
|
|
|
REGULAR,
|
|
|
|
SINGLE_AUTOMATIC
|
2022-03-29 21:49:32 +00:00
|
|
|
};
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
EnumNode<BusType> type;
|
2022-03-29 21:49:32 +00:00
|
|
|
IdentifierNode name;
|
2022-03-31 21:20:41 +00:00
|
|
|
std::optional<StringNode> tooltip;
|
|
|
|
std::optional<CountNode> count;
|
|
|
|
std::optional<DisplayNode> display;
|
2022-03-29 21:49:32 +00:00
|
|
|
|
|
|
|
std::vector<WireNode> wires;
|
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct LibraryNode: public AstNode
|
2022-03-29 21:49:32 +00:00
|
|
|
{
|
2022-03-31 21:20:41 +00:00
|
|
|
std::optional<StringNode> name;
|
|
|
|
std::optional<StringNode> libraryInfo;
|
|
|
|
std::optional<StringNode> header;
|
|
|
|
std::optional<StringNode> componentDirectory;
|
2022-03-29 21:49:32 +00:00
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
std::vector<AddressSpaceNode> addressSpaces;
|
2022-03-29 21:49:32 +00:00
|
|
|
|
|
|
|
std::vector<ComponentNode> components;
|
|
|
|
std::vector<BusNode> buses;
|
|
|
|
std::vector<ConnectionNode> connections;
|
|
|
|
|
|
|
|
std::vector<PropertyNode> messages;
|
|
|
|
};
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
// SCHEMA models
|
2022-04-09 17:44:02 +00:00
|
|
|
struct InstanceAttributeNode: public AstNode
|
2022-03-31 21:20:41 +00:00
|
|
|
{
|
|
|
|
IdentifierNode name;
|
|
|
|
ValueNode value;
|
|
|
|
};
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct InstanceNode: public AstNode
|
2022-03-31 21:20:41 +00:00
|
|
|
{
|
|
|
|
IdentifierNode name;
|
|
|
|
IdentifierNode component;
|
|
|
|
|
|
|
|
std::optional<CountNode> position;
|
|
|
|
std::vector<InstanceAttributeNode> attributes;
|
|
|
|
|
|
|
|
std::optional<NumberNode> size;
|
|
|
|
};
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
struct ConnectionComponentInstance: public AstNode
|
|
|
|
{
|
2022-03-31 21:20:41 +00:00
|
|
|
IdentifierNode instance;
|
|
|
|
IdentifierNode pin;
|
2022-04-09 17:44:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConnectionInstanceNode: public AstNode
|
|
|
|
{
|
|
|
|
ConnectionComponentInstance first;
|
|
|
|
std::optional<ConnectionComponentInstance> second;
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
IdentifierNode bus;
|
|
|
|
|
|
|
|
std::vector<InstanceAttributeNode> attributes;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
struct SchemaNode: public AstNode
|
2022-03-31 21:20:41 +00:00
|
|
|
{
|
|
|
|
std::optional<StringNode> source;
|
2022-03-29 21:49:32 +00:00
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
std::vector<InstanceNode> instances;
|
|
|
|
std::vector<ConnectionInstanceNode> connections;
|
|
|
|
|
|
|
|
std::optional<LibraryNode> library;
|
|
|
|
};
|
2022-03-29 21:49:32 +00:00
|
|
|
|
2022-04-08 18:17:58 +00:00
|
|
|
#endif // AST_NODE_H
|