]> gitweb.ps.run Git - toc/blob - src/repr.h
toc now uses internal representation instead of ast
[toc] / src / repr.h
1 #pragma once\r
2 \r
3 #include <vector>\r
4 #include <string>\r
5 #include <memory>\r
6 \r
7 #include "TocParser.h"\r
8 \r
9 using namespace std;\r
10 \r
11 struct Type;\r
12 struct Variable;\r
13 struct Body;\r
14 struct Function;\r
15 struct Struct;\r
16 struct Program;\r
17 struct CallExpr;\r
18 struct LiteralExpr;\r
19 struct VariableExpr;\r
20 struct BracketsExpr;\r
21 struct OperatorExpr;\r
22 struct DotExpr;\r
23 struct Expr;\r
24 struct IfStmt;\r
25 struct WhileStmt;\r
26 struct ReturnStmt;\r
27 struct AssignStmt;\r
28 struct Stmt;\r
29 \r
30 \r
31 struct Type {\r
32   std::string name;\r
33 };\r
34 \r
35 struct Variable {\r
36   std::string name;\r
37   Type type;\r
38 };\r
39 \r
40 struct Body {\r
41   std::vector<Variable> variables;\r
42   std::vector<Stmt> statements;\r
43 };\r
44 \r
45 struct Function {\r
46   Type returnType;\r
47   std::string name;\r
48   std::vector<Variable> parameters;\r
49   Body body;\r
50 };\r
51 \r
52 struct Struct {\r
53   std::string name;\r
54   std::vector<Variable> members;\r
55   std::vector<Function> methods;\r
56 };\r
57 \r
58 struct Program {\r
59   std::vector<Variable> variables;\r
60   std::vector<Struct> structs;\r
61   std::vector<Function> functions;\r
62 };\r
63 \r
64 enum class ExprType {\r
65   Call, Literal, Variable, Brackets, Operator, Dot\r
66 };\r
67 \r
68 struct CallExpr {\r
69   std::string functionName;\r
70   std::vector<Expr> arguments;\r
71 };\r
72 \r
73 struct LiteralExpr {\r
74   int i;\r
75 };\r
76 \r
77 struct VariableExpr {\r
78   std::string name;\r
79 };\r
80 \r
81 struct BracketsExpr {\r
82   std::shared_ptr<Expr> lexpr;\r
83   std::shared_ptr<Expr> rexpr;\r
84 };\r
85 \r
86 enum class OperatorType {\r
87   Plus, Minus, Multiply, Divide,\r
88   Equals, NotEquals,\r
89   LessThan, GreaterThan\r
90 };\r
91 \r
92 struct OperatorExpr {\r
93   std::shared_ptr<Expr> lexpr;\r
94   std::shared_ptr<Expr> rexpr;\r
95   OperatorType type;\r
96 };\r
97 \r
98 struct DotExpr {\r
99   std::shared_ptr<Expr> lexpr;\r
100   std::string name;\r
101 };\r
102 \r
103 struct Expr {\r
104   ExprType type;\r
105 \r
106   CallExpr     _call;\r
107   LiteralExpr  _literal;\r
108   VariableExpr _variable;\r
109   BracketsExpr _brackets;\r
110   OperatorExpr _operator;\r
111   DotExpr      _dot;\r
112 };\r
113 \r
114 enum class StmtType {\r
115   If, While, Return, Assign, Expr\r
116 };\r
117 \r
118 struct IfStmt {\r
119   Expr condition;\r
120   Body body;\r
121 };\r
122 \r
123 struct WhileStmt {\r
124   Expr condition;\r
125   Body body;\r
126 };\r
127 \r
128 struct ReturnStmt {\r
129   Expr expr;\r
130 };\r
131 \r
132 struct AssignStmt {\r
133   Expr lexpr;\r
134   Expr rexpr;\r
135 };\r
136 \r
137 struct Stmt {\r
138   StmtType type;\r
139   \r
140   IfStmt     _if;\r
141   WhileStmt  _while;\r
142   ReturnStmt _return;\r
143   AssignStmt _assign;\r
144   Expr       _expr;\r
145 };\r
146 \r
147 \r