7 #include "TocParser.h"
\r
24 struct PrefixOperatorExpr;
\r
25 struct PostfixOperatorExpr;
\r
26 struct BinaryOperatorExpr;
\r
27 struct TernaryOperatorExpr;
\r
28 struct BracketsExpr;
\r
29 struct IdentifierExpr;
\r
42 std::optional<std::string> name;
\r
43 std::shared_ptr<Context> parent;
\r
44 std::vector<Variable> variables;
\r
45 std::vector<Function> functions;
\r
46 std::vector<Struct> structs;
\r
47 std::vector<Namespace> namespaces;
\r
50 enum class TypeModifierType
\r
57 TypeModifierType type;
\r
65 std::vector<std::string> namespacePrefixes;
\r
67 std::vector<TypeModifier> modifiers;
\r
68 std::vector<Type> genericInstantiation;
\r
70 bool operator!=(const Type & that)
\r
72 if (this->name != that.name)
\r
75 for (int i = 0; i < this->modifiers.size(); i++)
\r
76 if (this->modifiers[i].type != that.modifiers[i].type)
\r
79 for (int i = 0; i < this->namespacePrefixes.size(); i++)
\r
80 if (this->namespacePrefixes[i] != that.namespacePrefixes[i])
\r
94 std::shared_ptr<Context> ctx;
\r
95 std::vector<Stmt> statements;
\r
102 std::vector<Variable> parameters;
\r
105 std::vector<std::string> genericTypeNames;
\r
106 std::vector<std::vector<Type>> genericInstantiations;
\r
111 template<typename T>
\r
112 struct StructMember
\r
116 operator T() { return t; }
\r
122 std::vector<std::string> genericTypeNames;
\r
123 std::vector<std::vector<Type>> genericInstantiations;
\r
124 std::vector<StructMember<Variable>> members;
\r
125 std::vector<StructMember<Function>> methods;
\r
131 std::shared_ptr<Context> ctx;
\r
136 std::shared_ptr<Context> ctx;
\r
139 enum class ExprType
\r
141 Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier
\r
146 std::vector<std::string> namespacePrefixes;
\r
147 std::string functionName;
\r
148 std::vector<Expr> arguments;
\r
149 std::vector<Type> genericInstantiation;
\r
154 std::shared_ptr<Expr> expr;
\r
155 std::string methodName;
\r
156 std::vector<Expr> arguments;
\r
157 std::vector<Type> genericInstantiation;
\r
162 Int, Decimal, String, Bool
\r
171 std::string _string;
\r
177 std::shared_ptr<Expr> expr;
\r
183 std::shared_ptr<Expr> expr;
\r
184 std::string identifier;
\r
187 enum class PrefixOperatorType
\r
189 Plus, Minus, Increment, Decrement,
\r
190 LogicalNot, BitwiseNot, Dereference, AddressOf,
\r
193 static std::string PrefixOperatorTypeStrings[] =
\r
195 "+", "-", "++", "--", "!", "~", "*", "&" };
\r
197 struct PrefixOperatorExpr
\r
199 PrefixOperatorType type;
\r
200 std::shared_ptr<Expr> expr;
\r
203 enum class PostfixOperatorType
\r
205 Increment, Decrement,
\r
208 static std::string PostfixOperatorTypeStrings[] =
\r
212 struct PostfixOperatorExpr
\r
214 PostfixOperatorType type;
\r
215 std::shared_ptr<Expr> expr;
\r
218 enum class BinaryOperatorType
\r
220 Plus, Minus, Multiply, Divide, Modulo, BitwiseAnd, BitwiseOr, BitwiseXor, LessThan, GreaterThan,
\r
221 LeftShift, RightShift, LogicalAnd, LogicalOr, Equals, NotEquals, LessThanEquals, GreaterThanEquals, BitwiseAndEquals, BitwiseOrEquals, BitwiseXorEquals,
\r
222 PlusEquals, MinusEquals, MultiplyEquals, DivideEquals, ModuloEquals,
\r
223 LeftShiftEquals, RightShiftEquals,
\r
226 static std::string BinaryOperatorTypeStrings[] =
\r
228 "+", "-", "*", "/", "%", "&", "|", "^", "<", ">",
\r
229 "<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=",
\r
230 "+=","-=","*=","/=","%=",
\r
233 struct BinaryOperatorExpr
\r
235 BinaryOperatorType type;
\r
236 std::shared_ptr<Expr> lexpr;
\r
237 std::shared_ptr<Expr> rexpr;
\r
240 struct TernaryOperatorExpr
\r
242 std::shared_ptr<Expr> lexpr;
\r
243 std::shared_ptr<Expr> rexprTrue;
\r
244 std::shared_ptr<Expr> rexprFalse;
\r
247 struct BracketsExpr
\r
249 std::shared_ptr<Expr> lexpr;
\r
250 std::shared_ptr<Expr> rexpr;
\r
253 struct IdentifierExpr
\r
255 std::vector<std::string> namespacePrefixes;
\r
256 std::string identifier;
\r
264 MethodExpr _method;
\r
268 PrefixOperatorExpr _prefixOp;
\r
269 PostfixOperatorExpr _postfixOp;
\r
270 BinaryOperatorExpr _binaryOp;
\r
271 TernaryOperatorExpr _ternaryOp;
\r
272 BracketsExpr _brackets;
\r
273 IdentifierExpr _identifier;
\r
276 enum class StmtType
\r
278 If, Switch, For, While, Assign, Return, Expr
\r
284 std::shared_ptr<Expr> expr;
\r
291 std::vector<ElseStmt> elses;
\r
296 std::shared_ptr<Expr> expr;
\r
302 std::shared_ptr<Expr> ident;
\r
303 std::vector<SwitchCase> cases;
\r
306 // TODO: int i = 0 (var decl)
\r
309 std::shared_ptr<AssignStmt> init;
\r
310 std::shared_ptr<Expr> condition;
\r
311 std::shared_ptr<Expr> action;
\r
336 SwitchStmt _switch;
\r
339 AssignStmt _assign;
\r
340 ReturnStmt _return;
\r