abouttreesummaryrefslogcommitdiff
path: root/src/repr.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/repr.h')
-rw-r--r--src/repr.h99
1 files changed, 66 insertions, 33 deletions
diff --git a/src/repr.h b/src/repr.h
index eb46e3a..47a78d7 100644
--- a/src/repr.h
+++ b/src/repr.h
@@ -33,65 +33,77 @@ struct AssignStmt;
struct ReturnStmt;
struct Stmt;
-enum class TypeModifierType {
+enum class TypeModifierType
+{
Pointer, Array
};
-struct TypeModifier {
+struct TypeModifier
+{
TypeModifierType type;
bool _staticArray;
int _arraySize;
};
-struct Type {
+struct Type
+{
std::string name;
std::vector<TypeModifier> modifiers;
};
-struct Variable {
+struct Variable
+{
std::string name;
Type type;
};
-struct Body {
+struct Body
+{
std::vector<Variable> variables;
std::vector<Stmt> statements;
};
-struct Function {
+struct Function
+{
Type returnType;
std::string name;
std::vector<Variable> parameters;
Body body;
};
-struct Struct {
+struct Struct
+{
std::string name;
std::vector<Variable> members;
std::vector<Function> methods;
};
-struct Program {
+struct Program
+{
std::vector<Variable> variables;
std::vector<Struct> structs;
std::vector<Function> functions;
};
-enum class ExprType {
+enum class ExprType
+{
Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot
};
-struct FuncExpr {
+struct FuncExpr
+{
std::string functionName;
std::vector<Expr> arguments;
};
-enum class LitType {
+enum class LitType
+{
Int, Decimal, String, Bool
};
-struct LitExpr {
+struct LitExpr
+{
LitType type;
int _int;
@@ -101,61 +113,72 @@ struct LitExpr {
};
// TODO: accessExpr
-struct IdentifierExpr {
+struct IdentifierExpr
+{
std::string name;
};
-struct BracketsExpr {
+struct BracketsExpr
+{
std::shared_ptr<Expr> lexpr;
std::shared_ptr<Expr> rexpr;
};
-enum class UnaryOperatorType {
+enum class UnaryOperatorType
+{
Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost,
LogicalNot, BitwiseNot, Dereference, AddressOf,
COUNT
};
-enum class BinaryOperatorType {
+enum class BinaryOperatorType
+{
Plus, Minus, Multiply, Divide, Modulo, BitwiseAnd, BitwiseOr, BitwiseXor, LessThan, GreaterThan,
LeftShift, RightShift, LogicalAnd, LogicalOr, Equals, NotEquals, LessThanEquals, GreaterThanEquals, BitwiseAndEquals, BitwiseOrEquals, BitwiseXorEquals,
PlusEquals, MinusEquals, MultiplyEquals, DivideEquals, ModuloEquals,
LeftShiftEquals, RightShiftEquals,
COUNT
};
-static std::string UnaryOperatorTypeStrings[] = {
+static std::string UnaryOperatorTypeStrings[] =
+{
"+", "-", "++", "--", "++", "--", "!", "~", "*", "&" };
-static std::string BinaryOperatorTypeStrings[] = {
+static std::string BinaryOperatorTypeStrings[] =
+{
"+", "-", "*", "/", "%", "&", "|", "^", "<", ">",
"<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=",
"+=","-=","*=","/=","%=",
"<<=",">>=" };
-struct UnaryOperatorExpr {
+struct UnaryOperatorExpr
+{
UnaryOperatorType type;
std::shared_ptr<Expr> expr;
};
-struct BinaryOperatorExpr {
+struct BinaryOperatorExpr
+{
BinaryOperatorType type;
std::shared_ptr<Expr> lexpr;
std::shared_ptr<Expr> rexpr;
};
-struct TernaryOperatorExpr {
+struct TernaryOperatorExpr
+{
std::shared_ptr<Expr> lexpr;
std::shared_ptr<Expr> rexprTrue;
std::shared_ptr<Expr> rexprFalse;
};
-struct DotExpr {
+struct DotExpr
+{
std::shared_ptr<Expr> expr;
IdentifierExpr ident;
};
// TODO: paren expr
-struct Expr {
+struct Expr
+{
ExprType type;
bool parenthesized;
@@ -170,33 +193,39 @@ struct Expr {
DotExpr _dot;
};
-enum class StmtType {
+enum class StmtType
+{
If, Switch, For, While, Assign, Return, Expr
};
-struct ElseStmt {
+struct ElseStmt
+{
bool _if;
std::shared_ptr<Expr> expr;
Body body;
};
-struct IfStmt {
+struct IfStmt
+{
Expr condition;
Body body;
std::vector<ElseStmt> elses;
};
-struct SwitchCase {
+struct SwitchCase
+{
std::shared_ptr<Expr> expr;
Body body;
};
-struct SwitchStmt {
+struct SwitchStmt
+{
IdentifierExpr ident;
std::vector<SwitchCase> cases;
};
// TODO: int i = 0 (var decl)
-struct ForStmt {
+struct ForStmt
+{
std::string varName;
std::shared_ptr<Expr> initValue;
std::shared_ptr<Expr> condition;
@@ -204,21 +233,25 @@ struct ForStmt {
Body body;
};
-struct WhileStmt {
+struct WhileStmt
+{
Expr condition;
Body body;
};
-struct AssignStmt {
+struct AssignStmt
+{
std::string name;
Expr expr;
};
-struct ReturnStmt {
+struct ReturnStmt
+{
Expr expr;
};
-struct Stmt {
+struct Stmt
+{
StmtType type;
IfStmt _if;