Format with clang

This commit is contained in:
2021-11-09 19:41:10 +01:00
parent ee016636f7
commit 61906b3c80
38 changed files with 2277 additions and 2364 deletions

View File

@@ -4,10 +4,10 @@
namespace Token
{
struct TokenizationError : public std::exception
{
Token errorToken;
std::string errorMsg;
TokenizationError(Token const & token, std::string const & msg);
};
struct TokenizationError : public std::exception
{
Token errorToken;
std::string errorMsg;
TokenizationError(Token const & token, std::string const & msg);
};
}

View File

@@ -3,27 +3,27 @@
namespace Token
{
enum class OperandType : int
{
Unknown = -1,
AddInteger = 0,
SubtractInteger,
DivideInteger,
MultiplyInteger,
ShiftIntegerLeft,
ShiftIntegerRight,
Jump,
CallFunction,
ReturnFromFunction,
ExitProgram,
LessThanInteger,
GreaterThanInteger,
EqualInteger,
SetInteger,
Interrupt,
PushInteger,
PopInteger
};
enum class OperandType : int
{
Unknown = -1,
AddInteger = 0,
SubtractInteger,
DivideInteger,
MultiplyInteger,
ShiftIntegerLeft,
ShiftIntegerRight,
Jump,
CallFunction,
ReturnFromFunction,
ExitProgram,
LessThanInteger,
GreaterThanInteger,
EqualInteger,
SetInteger,
Interrupt,
PushInteger,
PopInteger
};
OperandType GetOperandType(std::string const & op);
OperandType GetOperandType(std::string const & op);
}

View File

@@ -3,14 +3,14 @@
namespace Token
{
enum class RegisterType
{
Unknown = -1,
A = 0,
B,
C,
D
};
enum class RegisterType
{
Unknown = -1,
A = 0,
B,
C,
D
};
RegisterType GetRegisterType(std::string const & reg);
RegisterType GetRegisterType(std::string const & reg);
}

View File

@@ -7,47 +7,58 @@
namespace Token
{
enum class TokenValueType
{
None = 0,
Integer,
Operand,
Register,
String
};
enum class TokenValueType
{
None = 0,
Integer,
Operand,
Register,
String
};
struct Token
{
private:
Token(TokenType type, bool validness, int const lineNumber, int const lineColumn);
Token(TokenType type, std::string const & string, bool validness, int const lineNumber, int const lineColumn);
Token(TokenType type, int value, bool validness, int const lineNumber, int const lineColumn);
Token(TokenType type, RegisterType const registerType, bool validness, int const lineNumber, int const lineColumn);
Token(TokenType type, OperandType const OperandType, bool validness, int const lineNumber, int const lineColumn);
struct Token
{
private:
Token(TokenType type, bool validness, int const lineNumber, int const lineColumn);
Token(TokenType type, std::string const & string, bool validness, int const lineNumber, int const lineColumn);
Token(TokenType type, int value, bool validness, int const lineNumber, int const lineColumn);
Token(
TokenType type,
RegisterType const registerType,
bool validness,
int const lineNumber,
int const lineColumn);
Token(
TokenType type,
OperandType const OperandType,
bool validness,
int const lineNumber,
int const lineColumn);
public:
int const lineNumber;
int const lineColumn;
TokenType type;
TokenValueType const valueType;
bool isValid;
std::variant<OperandType, RegisterType, int, std::string> data;
std::string errorMessage;
public:
int const lineNumber;
int const lineColumn;
TokenType type;
TokenValueType const valueType;
bool isValid;
std::variant<OperandType, RegisterType, int, std::string> data;
std::string errorMessage;
Token(Token const & other);
Token(Token const & other);
static Token CreateEmptyToken(int const lineNumber, int const lineColumn);
static Token CreateErrorToken(std::string const & message, TokenType const type, int const lineNumber, int const lineColumn);
static Token CreateStatementEndToken(int const lineNumber, int const lineColumn);
static Token CreateLabelDefinitionToken(std::string const & string, int const lineNumber, int const lineColumn);
static Token CreateLabelArgumentToken(std::string const & string, int const lineNumber, int const lineColumn);
static Token CreateImmediateValueToken(int const value, int const lineNumber, int const lineColumn);
static Token CreateRegisterToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
static Token CreateOperandToken(OperandType const operandType, int const lineNumber, int const lineColumn);
static Token CreateMemoryToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
static Token CreateMemoryToken(int const value, int const lineNumber, int const lineColumn);
static Token CreateEmptyToken(int const lineNumber, int const lineColumn);
static Token
CreateErrorToken(std::string const & message, TokenType const type, int const lineNumber, int const lineColumn);
static Token CreateStatementEndToken(int const lineNumber, int const lineColumn);
static Token CreateLabelDefinitionToken(std::string const & string, int const lineNumber, int const lineColumn);
static Token CreateLabelArgumentToken(std::string const & string, int const lineNumber, int const lineColumn);
static Token CreateImmediateValueToken(int const value, int const lineNumber, int const lineColumn);
static Token CreateRegisterToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
static Token CreateOperandToken(OperandType const operandType, int const lineNumber, int const lineColumn);
static Token CreateMemoryToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
static Token CreateMemoryToken(int const value, int const lineNumber, int const lineColumn);
std::string GetName() const;
void Print() const;
};
std::string GetName() const;
void Print() const;
};
}

View File

@@ -5,19 +5,13 @@
namespace Token
{
class Tokenizer
{
private:
// Argument for string should never be of length zero
Token ExtractToken(
std::string const & string,
std::size_t const lineNumber,
std::size_t const lineColumn) const;
class Tokenizer {
private:
// Argument for string should never be of length zero
Token
ExtractToken(std::string const & string, std::size_t const lineNumber, std::size_t const lineColumn) const;
public:
void Tokenize(
std::string const & line,
std::size_t const lineNumber,
std::vector<Token> & tokens);
};
public:
void Tokenize(std::string const & line, std::size_t const lineNumber, std::vector<Token> & tokens);
};
}

View File

@@ -2,15 +2,15 @@
namespace Token
{
enum class TokenType
{
Unknown = -1,
Operand = 0,
ImmediateInteger,
Register,
StatementEnd,
LabelDefinition,
LabelArgument,
Memory
};
enum class TokenType
{
Unknown = -1,
Operand = 0,
ImmediateInteger,
Register,
StatementEnd,
LabelDefinition,
LabelArgument,
Memory
};
}