Skip to content

Commit 63001d3

Browse files
author
robertDurst
committed
some general code refactors
1 parent 384f72c commit 63001d3

34 files changed

+473
-689
lines changed

src/ast/Expression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Expression
1313
{
1414
GroupingExpression,
1515
NewExpression,
16-
UnaryExpression,
1716
PrimaryExpression,
17+
UnaryExpression,
1818
};
1919
virtual ExpressionType getExpressionType() = 0;
2020
};

src/ast/GeneralDefinition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class GeneralDefinition
1111
public:
1212
enum GeneralDefinitionType
1313
{
14-
ListDefinition,
1514
DictionaryDefinition,
15+
ListDefinition,
1616
NewUDTDefinition,
1717
PrimitiveDefition,
1818
};

src/ast/New.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class New
1111
public:
1212
enum NewType
1313
{
14-
ListLiteral,
1514
DictionaryLiteral,
15+
ListLiteral,
1616
UserDefinedType,
1717
};
1818
virtual NewType getNewType() = 0;

src/ast/Primary.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class Primary
1111
public:
1212
enum PrimaryType
1313
{
14-
IdentifierLiteral,
15-
StringLiteral,
16-
BooleanLiteral,
17-
IntegerLiteral,
18-
FloatLiteral,
1914
AttributeAccessLiteral,
2015
AttributeMethodAccessLiteral,
21-
MethodAccessLiteral,
16+
BooleanLiteral,
17+
FloatLiteral,
2218
FunctionCallLiteral,
19+
IdentifierLiteral,
20+
IntegerLiteral,
21+
MethodAccessLiteral,
22+
StringLiteral,
2323
};
2424
virtual PrimaryType getPrimaryType() = 0;
2525
};

src/ast/SourcePart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class SourcePart
1313
{
1414
GeneralDecleration,
1515
FunctionDefinitionPart,
16-
UserDefinedTypeDefinition,
1716
InitialExecutionBody,
17+
UserDefinedTypeDefinition,
1818
};
1919
// must defined a default value for the virtual function
2020
// https://stackoverflow.com/questions/307352/g-undefined-reference-to-typeinfo

src/ast/Statement.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class Statement
1010
public:
1111
enum StatementType
1212
{
13-
IfStatement,
14-
ReturnStatement,
13+
BinaryExpressionStatement,
1514
BlockStatement,
1615
GeneralDecleration,
17-
BinaryExpressionStatement,
16+
IfStatement,
17+
ReturnStatement,
1818
};
1919
virtual StatementType getStatementType() = 0;
2020
};

src/common/ReservedWords.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "ReservedWords.h"
66

77
bool
8-
isKeyword(std::string v)
8+
isKeyword(const std::string v)
99
{
1010
if (v == "fun" || v == "Cat" || v == "Cfn" || v == "dec" || v == "exp" ||
1111
v == "if" || v == "else" || v == "return" || v == "import" ||
@@ -16,7 +16,7 @@ isKeyword(std::string v)
1616
}
1717

1818
bool
19-
isPrimitive(std::string type)
19+
isPrimitive(const std::string type)
2020
{
2121
if (type == "int" || type == "flt" || type == "str" || type == "bool" ||
2222
type == "void")

src/common/ReservedWords.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
#pragma once
66
#include <string>
77

8-
bool isKeyword(std::string);
9-
bool isPrimitive(std::string);
8+
bool isKeyword(const std::string);
9+
bool isPrimitive(const std::string);

src/errorhandler/Error.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,22 @@
99
class Error
1010
{
1111
private:
12-
int line;
12+
int lineNumber;
1313
std::string msg;
1414
std::string errtype;
1515

1616
public:
1717
// constructor
18-
Error(int l, std::string m)
18+
Error(const int l, const std::string m)
1919
{
20-
line = l;
20+
lineNumber = l;
2121
msg = m;
2222
}
2323
// destructor
24-
~Error()
25-
{
26-
}
24+
~Error(){};
2725
// set method for receiving type to utilize internally
2826
void
29-
setErrorType(std::string e)
27+
setErrorType(const std::string e)
3028
{
3129
errtype = e;
3230
}
@@ -35,7 +33,7 @@ class Error
3533
std::string
3634
getPrettyMessage()
3735
{
38-
return "[" + errtype + " Error at line: " + std::to_string(line) +
36+
return "[" + errtype + " Error at line: " + std::to_string(lineNumber) +
3937
"]: " + msg + "\n";
4038
}
4139
// get methods

src/lexar/Lexar.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ createTokenPutback(Kind k, char c, std::string buffer, Scanner* scanner,
1717
int linenum, int colNum)
1818
{
1919
if (!isspace(c))
20-
{
2120
buffer.pop_back();
22-
}
21+
2322
scanner->putBackChar(c);
2423
return new Token(k, buffer, linenum, colNum);
2524
}
2625

27-
Lexar::Lexar(std::string filename)
26+
Lexar::Lexar(const std::string filename)
2827
{
2928
scanner = new Scanner(filename);
3029
currentLineNum = 0;
@@ -66,24 +65,20 @@ Lexar::getNextToken()
6665
else
6766
{
6867
if (state == State::STRING || !isspace(c))
69-
{
7068
buffer += c;
71-
}
69+
7270
switch (state)
7371
{
7472
case State::START:
7573
if (isalpha(c))
76-
{
7774
state = State::IDENTIFIER;
78-
}
75+
7976
else if (isdigit(c))
80-
{
8177
state = State::INTEGER;
82-
}
78+
8379
else if (isspace(c))
84-
{
8580
state = State::START;
86-
}
81+
8782
else
8883
{
8984
switch (c)

0 commit comments

Comments
 (0)