This commit is contained in:
Borna Rajkovic committed 2022-04-08 21:07:29 +02:00
1 parent 0a0b20a156
commit 9bd68ecf23
25 files changed
+67 -130

No files matched your search

-1
View File
@@ -1 +0,0 @@
#include "assert.h"
-36
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
+7 -7
View File
@@ -1,13 +1,13 @@
#ifndef ASTNODE_H
#define ASTNODE_H
#ifndef AST_NODE_H
#define AST_NODE_H
#include "token.h"
#include <optional>
#include <vector>
/**
* AST base class, all AST node classes extand this class. Class contains basic
* information about a nodes location in file.
* AST base class, all AST node classes extend this class. Class contains basic
* information about nodes location in file.
*/
class AstNode {
public:
@@ -175,7 +175,7 @@ public:
};
struct IfStatementnode: AstNode
struct IfStatementNode: AstNode
{
ConditionNode condition;
ActionNode action;
@@ -184,7 +184,7 @@ struct IfStatementnode: AstNode
struct RuleNode: AstNode
{
std::vector<IfStatementnode> statements;
std::vector<IfStatementNode> statements;
};
@@ -400,4 +400,4 @@ struct SchemaNode: AstNode
std::optional<LibraryNode> library;
};
#endif // ASTNODE_H
#endif // AST_NODE_H
+9 -9
View File
@@ -39,7 +39,7 @@ ComdelLexer::ComdelLexer(std::string fileName, std::string source,
ParseContext* parseContext)
: source(std::move(source)),
parseContext(parseContext),
// qqq zamijeniti poziv path_absolute sa Qt-ovim pozivom
// TODO Update this
fileId(this->parseContext->addFile(fileName, this->source)),
position(this->fileId, 1, 1, 0),
ch(this->source[0])
@@ -101,8 +101,8 @@ unsigned ComdelLexer::takeNumberInRadix(Radix radix) {
bool ComdelLexer::digitIsValid(char ch, Radix radix) {
// Check digits in normal numbers
//digit is 0..1
// Check valid digits
// digit is 0..1
if(ch == '1' || ch == '0') {
// OK for all radixes
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 digitsTaken = 0;
@@ -159,7 +159,7 @@ PResult<TokenType> ComdelLexer::takeString() {
return PError({Span(lo), "expected string here"});
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.
while (ch != '"' && ch != '\n' && !eof()) {
if(ch == '"') {
@@ -189,7 +189,7 @@ PResult<TokenType> ComdelLexer::takeRawString()
return PError({Span(lo), "expected string here"});
bump(); // skip starting '
// Ignore ecsape-sequences - take all characters until closing '
// Ignore escape-sequences - take all characters until closing '
while (ch != '`' && !eof()) {
bump(); // skip characters
}
@@ -299,7 +299,7 @@ PResult<TokenType> ComdelLexer::nextTokenType() {
return TokenType::COLOR;
} else {
return PError({Span(tokenBegin, position),
"unexpected #"});;
"unexpected #"});
}
}
else if (ch == '@')
@@ -366,7 +366,7 @@ PResult<TokenType> ComdelLexer::nextTokenType() {
return TokenType::COMMENT;
}
return PError({Span(tokenBegin, position),
"unexpected /"});;
"unexpected /"});
}
else if (ch == '.')
{
@@ -431,7 +431,7 @@ void ComdelLexer::bump(unsigned count) {
// Fetch and return next character without moving position.
// 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() {
if(position.offset+1 == source.size()) // eof
return '\n';
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef COMDELLEXER_H
#define COMDELLEXER_H
#ifndef COMDEL_LEXER_H
#define COMDEL_LEXER_H
#include "parsecontext.h"
#include "presult.h"
@@ -60,4 +60,4 @@ private:
bool eof();
};
#endif // COMDELLEXER_H
#endif // COMDEL_LEXER_H
+6 -8
View File
@@ -1,13 +1,11 @@
#include "comdelparser.h"
#include "assert.h"
#include "poly.h"
#include "tokenstype.h"
#include <utility>
#include <algorithm>
#include <fstream>
#include <cctype>
#include <sstream>
ComdelParser::ComdelParser(std::vector<Token> tokens)
@@ -107,12 +105,12 @@ PError ComdelParser::unexpected() {
//
// '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.
//
// Parameter allowTrailing==true means that the list should ends with
// 'separator' and otherwise the list should ends with 'node'. This
// Parameter allowTrailing==true means that the list should end with
// 'separator' and otherwise the list should end with 'node'. This
// parameter is false in every call-site!
template<typename T> PResult<std::vector<T>>
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()
@@ -917,9 +915,9 @@ PResult<RuleNode> ComdelParser::parseRule() {
* IfStatement := "if(!function(params...)) { error(MESSAGE) | warning(MESSAGE) }
*
****************************************************************************/
PResult<IfStatementnode> ComdelParser::parseIfStatement() {
PResult<IfStatementNode> ComdelParser::parseIfStatement() {
auto spanner = getSpanner();
IfStatementnode ifStatement;
IfStatementNode ifStatement;
RETURN_IF_NOT_TOKEN(TokenType::IF);
+4 -5
View File
@@ -1,5 +1,5 @@
#ifndef COMDELPARSER_H
#define COMDELPARSER_H
#ifndef COMDEL_PARSER_H
#define COMDEL_PARSER_H
#include "sourceerror.h"
#include "presult.h"
@@ -61,7 +61,6 @@ private:
Spanner getSpanner();
void parseBlock();
PResult<StringNode> parseString();
PResult<IdentifierNode> parseIdentifier();
@@ -82,7 +81,7 @@ private:
PResult<WireNode> parseWire();
PResult<ConnectionNode> parseConnection();
PResult<DisplayItemNode> parseDisplayItem();
PResult<IfStatementnode> parseIfStatement();
PResult<IfStatementNode> parseIfStatement();
PResult<ValueNode> parseValue();
PResult<WireInstanceNode> parseWireInstance();
@@ -98,4 +97,4 @@ public:
const std::vector<SourceError>& getErrors();
};
#endif // COMDELPARSER_H
#endif // COMDEL_PARSER_H
+1 -1
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
// 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
// `expected`
template <class T, class E, bool = std::is_trivially_destructible<T>::value,
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef PARSECONTEXT_H
#define PARSECONTEXT_H
#ifndef PARSE_CONTEXT_H
#define PARSE_CONTEXT_H
#include "sourceerror.h"
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef PARSERUTIL_H
#define PARSERUTIL_H
#ifndef PARSER_UTIL_H
#define PARSER_UTIL_H
#include "astnode.h"
#include "parsecontext.h"
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef SOURCEERROR_H
#define SOURCEERROR_H
#ifndef SOURCE_ERROR_H
#define SOURCE_ERROR_H
#include "token.h"
#include <string>
@@ -11,4 +11,4 @@ struct SourceError {
SourceError(Span span, std::string message);
};
#endif // SOURCEERROR_H
#endif // SOURCE_ERROR_H
+1 -11
View File
@@ -157,14 +157,4 @@ TokenType TokenTables::tokenize(std::string value, TokenType initial) {
TokenType from_token(std::string value, TokenType 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;
}
}
+3 -6
View File
@@ -1,5 +1,5 @@
#ifndef TOKENSTYPE_H
#define TOKENSTYPE_H
#ifndef TOKENS_TYPE_H
#define TOKENS_TYPE_H
#include "token.h"
@@ -8,9 +8,6 @@
const std::string& tokenTypeToString(TokenType tokenType);
bool isBuiltInFunc(TokenType tokenType);
bool isDataType(TokenType tokenType);
TokenType from_token(std::string value, TokenType initial);
#endif // TOKENSTYPE_H
#endif // TOKENS_TYPE_H