This commit is contained in:
Borna Rajkovic 2022-04-08 20:17:58 +02:00
parent 0a0b20a156
commit 9bd68ecf23
25 changed files with 67 additions and 130 deletions

View File

@ -28,8 +28,7 @@ add_executable(SchemeEditor
comdel/domain/connection.cpp comdel/domain/connection.cpp
comdel/domain/instance.cpp comdel/domain/instance.cpp
comdel/domain/comdelgenerator.cpp comdel/domain/comdelgenerator.cpp
comdel/parser/assert.cpp comdel/parser/comdelparser.cpp
comdel/parser/comdelparser.cpp
comdel/parser/token.cpp comdel/parser/token.cpp
comdel/parser/parser_util.cpp comdel/parser/parser_util.cpp
comdel/parser/sourceerror.cpp comdel/parser/sourceerror.cpp

View File

@ -7,19 +7,19 @@ Component *Component::ofWire(domain::WireInstance *wire) {
component->wireInstance = wire; component->wireInstance = wire;
component->redraw(); component->redraw();
return component; return component;
}; }
Component *Component::ofComponent(domain::ComponentInstance *instance) { Component *Component::ofComponent(domain::ComponentInstance *instance) {
auto component = new Component(); auto component = new Component();
component->componentInstance = instance; component->componentInstance = instance;
component->redraw(); component->redraw();
return component; return component;
}; }
Component *Component::ofBus(domain::BusInstance *instance) { Component *Component::ofBus(domain::BusInstance *instance) {
auto component = new Component(); auto component = new Component();
component->busInstance = instance; component->busInstance = instance;
component->redraw(); component->redraw();
return component; return component;
}; }
void Component::redraw() { void Component::redraw() {
if(componentInstance) { if(componentInstance) {

View File

@ -1,10 +1,8 @@
#ifndef DOMAIN_ADDRESSSPACE_H #ifndef DOMAIN_ADDRESS_SPACE_H
#define DOMAIN_ADDRESSSPACE_H #define DOMAIN_ADDRESS_SPACE_H
#include <string> #include <string>
namespace domain { namespace domain {
class AddressSpace class AddressSpace
@ -23,4 +21,4 @@ public:
} // namespace domain } // namespace domain
#endif // DOMAIN_ADDRESSSPACE_H #endif // DOMAIN_ADDRESS_SPACE_H

View File

@ -432,7 +432,7 @@ std::optional<Display> ComdelGenerator::loadDisplay(DisplayNode node)
h = getIntProperty(item, "h"); h = getIntProperty(item, "h");
displayItem.pin = ui::Pin(x, y, w, h); displayItem.pin = ui::Pin(x, y, w, h);
} else { } else {
errors.push_back(SourceError{item.type.span, "unsuported display type"}); errors.push_back(SourceError{item.type.span, "unsupported display type"});
} }
items.push_back(displayItem); items.push_back(displayItem);
} }
@ -537,7 +537,7 @@ std::optional<Popup> ComdelGenerator::loadPopup(PopupNode node, std::string name
} }
} else { } else {
if(type == Value::WIRE_REFERENCE && !current().inConnection) { if(type == Value::WIRE_REFERENCE && !current().inConnection) {
errors.push_back(SourceError{node.span, "@enumeration is required for atributes of type wire"}); errors.push_back(SourceError{node.span, "@enumeration is required for attributes of type wire"});
} }
} }
@ -594,7 +594,7 @@ std::optional<Condition> ComdelGenerator::loadCondition(ConditionNode node)
} }
return Condition(function, params, node.negated); return Condition(function, params, node.negated);
} else { } else {
errors.push_back(SourceError{node.functionName.span, "wrong number of parametars"}); errors.push_back(SourceError{node.functionName.span, "wrong number of parameters"});
} }
} }
} }

View File

@ -1,5 +1,5 @@
#ifndef DOMAIN_COMDELGENERATOR_H #ifndef DOMAIN_COMDEL_GENERATOR_H
#define DOMAIN_COMDELGENERATOR_H #define DOMAIN_COMDEL_GENERATOR_H
#include "library.h" #include "library.h"
#include "schema.h" #include "schema.h"
@ -143,4 +143,4 @@ public:
} // namespace domain } // namespace domain
#endif // DOMAIN_COMDELGENERATOR_H #endif // DOMAIN_COMDEL_GENERATOR_H

View File

@ -11,7 +11,7 @@ BusConnectionInstance::BusConnectionInstance(ComponentInstance *instance, std::v
: ConnectionInstance(instance, attributes, wire, connection), bus(bus) : ConnectionInstance(instance, attributes, wire, connection), bus(bus)
{} {}
DirectConnectionInstance::DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondsInstance, std::vector<InstanceAttribute*> attributes, BusInstance *bus, WireInstance *wire, Connection connection) DirectConnectionInstance::DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondInstance, std::vector<InstanceAttribute*> attributes, BusInstance *bus, WireInstance *wire, Connection connection)
: ConnectionInstance(instance, attributes, wire, connection), secondInstance(secondInstance), bus(bus) : ConnectionInstance(instance, attributes, wire, connection), secondInstance(secondInstance), bus(bus)
{} {}

View File

@ -1,5 +1,5 @@
#ifndef DOMAIN_CONNECTIONINSTANCE_H #ifndef DOMAIN_CONNECTION_INSTANCE_H
#define DOMAIN_CONNECTIONINSTANCE_H #define DOMAIN_CONNECTION_INSTANCE_H
#include "connection.h" #include "connection.h"
#include "instance.h" #include "instance.h"

View File

@ -1,5 +1,5 @@
#ifndef DOMAIN_FUNCTIONSIGNATURE_H #ifndef DOMAIN_FUNCTION_SIGNATURE_H
#define DOMAIN_FUNCTIONSIGNATURE_H #define DOMAIN_FUNCTION_SIGNATURE_H
#include<functional> #include<functional>
#include "value.h" #include "value.h"

View File

@ -1,5 +1,5 @@
#ifndef DOMAIN_INSTANCEATTRIBUTE_H #ifndef DOMAIN_INSTANCE_ATTRIBUTE_H
#define DOMAIN_INSTANCEATTRIBUTE_H #define DOMAIN_INSTANCE_ATTRIBUTE_H
#include "attribute.h" #include "attribute.h"
#include "value.h" #include "value.h"
@ -23,4 +23,4 @@ public:
} // namespace domain } // namespace domain
#endif // DOMAIN_INSTANCEATTRIBUTE_H #endif // DOMAIN_INSTANCE_ATTRIBUTE_H

View File

@ -1,5 +1,5 @@
#ifndef DOMAIN_WIREINSTANCE_H #ifndef DOMAIN_WIRE_INSTANCE_H
#define DOMAIN_WIREINSTANCE_H #define DOMAIN_WIRE_INSTANCE_H
#include "display.h" #include "display.h"

View File

@ -1 +0,0 @@
#include "assert.h"

View File

@ -1,36 +0,0 @@
#ifndef ASSERT_H
#define ASSERT_H
#include <string>
class AtlasException : public std::exception {
const std::string fileName;
const int fileLine;
const std::string message;
protected:
virtual void buildString(std::ostream& stream) const;
std::string fullMessage;
public:
explicit AtlasException(const std::string& file, int line,
const std::string& msg);
virtual ~AtlasException() {
}
virtual std::string buildMessage() const;
virtual std::string toString() const {
return fullMessage;
}
virtual const char* what() const noexcept {
return fullMessage.c_str();
}
};
#endif // ASSERT_H

View File

@ -1,13 +1,13 @@
#ifndef ASTNODE_H #ifndef AST_NODE_H
#define ASTNODE_H #define AST_NODE_H
#include "token.h" #include "token.h"
#include <optional> #include <optional>
#include <vector> #include <vector>
/** /**
* AST base class, all AST node classes extand this class. Class contains basic * AST base class, all AST node classes extend this class. Class contains basic
* information about a nodes location in file. * information about nodes location in file.
*/ */
class AstNode { class AstNode {
public: public:
@ -175,7 +175,7 @@ public:
}; };
struct IfStatementnode: AstNode struct IfStatementNode: AstNode
{ {
ConditionNode condition; ConditionNode condition;
ActionNode action; ActionNode action;
@ -184,7 +184,7 @@ struct IfStatementnode: AstNode
struct RuleNode: AstNode struct RuleNode: AstNode
{ {
std::vector<IfStatementnode> statements; std::vector<IfStatementNode> statements;
}; };
@ -400,4 +400,4 @@ struct SchemaNode: AstNode
std::optional<LibraryNode> library; std::optional<LibraryNode> library;
}; };
#endif // ASTNODE_H #endif // AST_NODE_H

View File

@ -39,7 +39,7 @@ ComdelLexer::ComdelLexer(std::string fileName, std::string source,
ParseContext* parseContext) ParseContext* parseContext)
: source(std::move(source)), : source(std::move(source)),
parseContext(parseContext), parseContext(parseContext),
// qqq zamijeniti poziv path_absolute sa Qt-ovim pozivom // TODO Update this
fileId(this->parseContext->addFile(fileName, this->source)), fileId(this->parseContext->addFile(fileName, this->source)),
position(this->fileId, 1, 1, 0), position(this->fileId, 1, 1, 0),
ch(this->source[0]) ch(this->source[0])
@ -101,8 +101,8 @@ unsigned ComdelLexer::takeNumberInRadix(Radix radix) {
bool ComdelLexer::digitIsValid(char ch, Radix radix) { bool ComdelLexer::digitIsValid(char ch, Radix radix) {
// Check digits in normal numbers // Check valid digits
//digit is 0..1 // digit is 0..1
if(ch == '1' || ch == '0') { if(ch == '1' || ch == '0') {
// OK for all radixes // OK for all radixes
return true; return true;
@ -137,7 +137,7 @@ ComdelLexer::Radix ComdelLexer::takeRadix(){
} }
// color is sequence of hex-digits (preceeded with # which is already consumed) // color is sequence of hex-digits (preceded with # which is already consumed)
unsigned ComdelLexer::takeHexColor() { unsigned ComdelLexer::takeHexColor() {
unsigned digitsTaken = 0; unsigned digitsTaken = 0;
@ -159,7 +159,7 @@ PResult<TokenType> ComdelLexer::takeString() {
return PError({Span(lo), "expected string here"}); return PError({Span(lo), "expected string here"});
bump(); // skip starting " bump(); // skip starting "
// Check ecsape-sequences \t \n \\ \" but leave them in string. // Check escape-sequences \t \n \\ \" but leave them in string.
// They will be replaced in the constructor of StringLiteral AST-node. // They will be replaced in the constructor of StringLiteral AST-node.
while (ch != '"' && ch != '\n' && !eof()) { while (ch != '"' && ch != '\n' && !eof()) {
if(ch == '"') { if(ch == '"') {
@ -189,7 +189,7 @@ PResult<TokenType> ComdelLexer::takeRawString()
return PError({Span(lo), "expected string here"}); return PError({Span(lo), "expected string here"});
bump(); // skip starting ' bump(); // skip starting '
// Ignore ecsape-sequences - take all characters until closing ' // Ignore escape-sequences - take all characters until closing '
while (ch != '`' && !eof()) { while (ch != '`' && !eof()) {
bump(); // skip characters bump(); // skip characters
} }
@ -299,7 +299,7 @@ PResult<TokenType> ComdelLexer::nextTokenType() {
return TokenType::COLOR; return TokenType::COLOR;
} else { } else {
return PError({Span(tokenBegin, position), return PError({Span(tokenBegin, position),
"unexpected #"});; "unexpected #"});
} }
} }
else if (ch == '@') else if (ch == '@')
@ -366,7 +366,7 @@ PResult<TokenType> ComdelLexer::nextTokenType() {
return TokenType::COMMENT; return TokenType::COMMENT;
} }
return PError({Span(tokenBegin, position), return PError({Span(tokenBegin, position),
"unexpected /"});; "unexpected /"});
} }
else if (ch == '.') else if (ch == '.')
{ {
@ -431,7 +431,7 @@ void ComdelLexer::bump(unsigned count) {
// Fetch and return next character without moving position. // Fetch and return next character without moving position.
// Fetch does not cross line boundary. // Fetch does not cross line boundary.
// Returns \n when next char does not exists (end of line or end of file) // Returns \n when next char does not exist (end of line or end of file)
char ComdelLexer::peek() { char ComdelLexer::peek() {
if(position.offset+1 == source.size()) // eof if(position.offset+1 == source.size()) // eof
return '\n'; return '\n';

View File

@ -1,5 +1,5 @@
#ifndef COMDELLEXER_H #ifndef COMDEL_LEXER_H
#define COMDELLEXER_H #define COMDEL_LEXER_H
#include "parsecontext.h" #include "parsecontext.h"
#include "presult.h" #include "presult.h"
@ -60,4 +60,4 @@ private:
bool eof(); bool eof();
}; };
#endif // COMDELLEXER_H #endif // COMDEL_LEXER_H

View File

@ -1,13 +1,11 @@
#include "comdelparser.h" #include "comdelparser.h"
#include "assert.h"
#include "poly.h" #include "poly.h"
#include "tokenstype.h" #include "tokenstype.h"
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <cctype>
#include <sstream> #include <sstream>
ComdelParser::ComdelParser(std::vector<Token> tokens) ComdelParser::ComdelParser(std::vector<Token> tokens)
@ -107,12 +105,12 @@ PError ComdelParser::unexpected() {
// //
// 'openDelim' and 'separator' are optional (could be nullopt). // 'openDelim' and 'separator' are optional (could be nullopt).
// //
// 'closeDelim' is mandatory and it will be consumed. // 'closeDelim' is mandatory, and it will be consumed.
// //
// Function 'parse_f' should only parse a single node of type T. // Function 'parse_f' should only parse a single node of type T.
// //
// Parameter allowTrailing==true means that the list should ends with // Parameter allowTrailing==true means that the list should end with
// 'separator' and otherwise the list should ends with 'node'. This // 'separator' and otherwise the list should end with 'node'. This
// parameter is false in every call-site! // parameter is false in every call-site!
template<typename T> PResult<std::vector<T>> template<typename T> PResult<std::vector<T>>
ComdelParser::parseList(std::optional<TokenType> openDelim, ComdelParser::parseList(std::optional<TokenType> openDelim,
@ -374,7 +372,7 @@ PResult<PropertyNode> ComdelParser::parseProperty(std::optional<TokenType> value
/**************************************************************************** /****************************************************************************
* *
* AddressSpaceNode := "@address" + IDENTIFIER "(" + NUMER + "," + NUMBER + ")" * AddressSpaceNode := "@address" + IDENTIFIER "(" + NUMBER + "," + NUMBER + ")"
* *
****************************************************************************/ ****************************************************************************/
PResult<AddressSpaceNode> ComdelParser::parseAddress() PResult<AddressSpaceNode> ComdelParser::parseAddress()
@ -917,9 +915,9 @@ PResult<RuleNode> ComdelParser::parseRule() {
* IfStatement := "if(!function(params...)) { error(MESSAGE) | warning(MESSAGE) } * IfStatement := "if(!function(params...)) { error(MESSAGE) | warning(MESSAGE) }
* *
****************************************************************************/ ****************************************************************************/
PResult<IfStatementnode> ComdelParser::parseIfStatement() { PResult<IfStatementNode> ComdelParser::parseIfStatement() {
auto spanner = getSpanner(); auto spanner = getSpanner();
IfStatementnode ifStatement; IfStatementNode ifStatement;
RETURN_IF_NOT_TOKEN(TokenType::IF); RETURN_IF_NOT_TOKEN(TokenType::IF);

View File

@ -1,5 +1,5 @@
#ifndef COMDELPARSER_H #ifndef COMDEL_PARSER_H
#define COMDELPARSER_H #define COMDEL_PARSER_H
#include "sourceerror.h" #include "sourceerror.h"
#include "presult.h" #include "presult.h"
@ -61,7 +61,6 @@ private:
Spanner getSpanner(); Spanner getSpanner();
void parseBlock();
PResult<StringNode> parseString(); PResult<StringNode> parseString();
PResult<IdentifierNode> parseIdentifier(); PResult<IdentifierNode> parseIdentifier();
@ -82,7 +81,7 @@ private:
PResult<WireNode> parseWire(); PResult<WireNode> parseWire();
PResult<ConnectionNode> parseConnection(); PResult<ConnectionNode> parseConnection();
PResult<DisplayItemNode> parseDisplayItem(); PResult<DisplayItemNode> parseDisplayItem();
PResult<IfStatementnode> parseIfStatement(); PResult<IfStatementNode> parseIfStatement();
PResult<ValueNode> parseValue(); PResult<ValueNode> parseValue();
PResult<WireInstanceNode> parseWireInstance(); PResult<WireInstanceNode> parseWireInstance();
@ -98,4 +97,4 @@ public:
const std::vector<SourceError>& getErrors(); const std::vector<SourceError>& getErrors();
}; };
#endif // COMDELPARSER_H #endif // COMDEL_PARSER_H

View File

@ -345,7 +345,7 @@ static constexpr no_init_t no_init{};
// Implements the storage of the values, and ensures that the destructor is // Implements the storage of the values, and ensures that the destructor is
// trivial if it can be. // trivial if it can be.
// //
// This specialization is for where neither `T` or `E` is trivially // This specialization is for where neither `T` nor `E` is trivially
// destructible, so the destructors must be called on destruction of the // destructible, so the destructors must be called on destruction of the
// `expected` // `expected`
template <class T, class E, bool = std::is_trivially_destructible<T>::value, template <class T, class E, bool = std::is_trivially_destructible<T>::value,

View File

@ -1,5 +1,5 @@
#ifndef PARSECONTEXT_H #ifndef PARSE_CONTEXT_H
#define PARSECONTEXT_H #define PARSE_CONTEXT_H
#include "sourceerror.h" #include "sourceerror.h"

View File

@ -1,5 +1,5 @@
#ifndef PARSERUTIL_H #ifndef PARSER_UTIL_H
#define PARSERUTIL_H #define PARSER_UTIL_H
#include "astnode.h" #include "astnode.h"
#include "parsecontext.h" #include "parsecontext.h"

View File

@ -1,5 +1,5 @@
#ifndef SOURCEERROR_H #ifndef SOURCE_ERROR_H
#define SOURCEERROR_H #define SOURCE_ERROR_H
#include "token.h" #include "token.h"
#include <string> #include <string>
@ -11,4 +11,4 @@ struct SourceError {
SourceError(Span span, std::string message); SourceError(Span span, std::string message);
}; };
#endif // SOURCEERROR_H #endif // SOURCE_ERROR_H

View File

@ -157,14 +157,4 @@ TokenType TokenTables::tokenize(std::string value, TokenType initial) {
TokenType from_token(std::string value, TokenType initial) { TokenType from_token(std::string value, TokenType initial) {
return tokenTables.tokenize(value, initial); return tokenTables.tokenize(value, initial);
} }
bool isBuiltInFunc(TokenType tokenType)
{
return tokenTables.allTokensInfo[tokenType].attributes & BUILT_IN_FUNC;
}
bool isKeyword(TokenType tokenType)
{
return tokenTables.allTokensInfo[tokenType].attributes & KEYWORD_NAME;
}

View File

@ -1,5 +1,5 @@
#ifndef TOKENSTYPE_H #ifndef TOKENS_TYPE_H
#define TOKENSTYPE_H #define TOKENS_TYPE_H
#include "token.h" #include "token.h"
@ -8,9 +8,6 @@
const std::string& tokenTypeToString(TokenType tokenType); const std::string& tokenTypeToString(TokenType tokenType);
bool isBuiltInFunc(TokenType tokenType);
bool isDataType(TokenType tokenType);
TokenType from_token(std::string value, TokenType initial); TokenType from_token(std::string value, TokenType initial);
#endif // TOKENSTYPE_H #endif // TOKENS_TYPE_H

View File

@ -2,13 +2,6 @@
#include <QApplication> #include <QApplication>
#include <iostream>
#include <comdel/parser/parsecontext.h>
#include <comdel/parser/parserutil.h>
#include <comdel/domain/comdelgenerator.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {

View File

@ -1,5 +1,5 @@
#ifndef MAINWINDOW_H #ifndef MAIN_WINDOW_H
#define MAINWINDOW_H #define MAIN_WINDOW_H
#include <QListWidget> #include <QListWidget>
#include <QMainWindow> #include <QMainWindow>
@ -41,4 +41,4 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
}; };
#endif // MAINWINDOW_H #endif // MAIN_WINDOW_H