7 #include "TocParser.h"
\r
11 // This contains a 1 to 1 representation of the defined language
\r
26 struct PrefixOperatorExpr;
\r
27 struct PostfixOperatorExpr;
\r
28 struct BinaryOperatorExpr;
\r
29 struct TernaryOperatorExpr;
\r
30 struct BracketsExpr;
\r
31 struct IdentifierExpr;
\r
42 // Context is a collection of everything that can be defined in a namespace
\r
43 // that is reused for bodies so that the hierarchy can be walked uniformly
\r
44 // both up and down using the parent variable
\r
47 std::optional<std::string> name;
\r
48 std::shared_ptr<Context> parent;
\r
49 std::vector<Variable> variables;
\r
50 std::vector<Function> functions;
\r
51 std::vector<Struct> structs;
\r
52 std::vector<Namespace> namespaces;
\r
55 enum class TypeModifierType
\r
62 TypeModifierType type;
\r
70 std::vector<std::string> namespacePrefixes;
\r
72 std::vector<TypeModifier> modifiers;
\r
73 std::vector<Type> genericInstantiation;
\r
75 bool operator!=(const Type & that)
\r
77 if (this->name != that.name)
\r
80 for (int i = 0; i < this->modifiers.size(); i++)
\r
81 if (this->modifiers[i].type != that.modifiers[i].type)
\r
84 for (int i = 0; i < this->namespacePrefixes.size(); i++)
\r
85 if (this->namespacePrefixes[i] != that.namespacePrefixes[i])
\r
99 std::shared_ptr<Context> ctx;
\r
100 std::vector<Stmt> statements;
\r
107 std::vector<Variable> parameters;
\r
110 std::vector<std::string> genericTypeNames;
\r
111 std::vector<std::vector<Type>> genericInstantiations;
\r
116 template<typename T>
\r
117 struct StructMember
\r
121 operator T() { return t; }
\r
127 std::vector<std::string> genericTypeNames;
\r
128 std::vector<std::vector<Type>> genericInstantiations;
\r
129 std::vector<StructMember<Variable>> members;
\r
130 std::vector<StructMember<Function>> methods;
\r
136 std::shared_ptr<Context> ctx;
\r
141 std::shared_ptr<Context> ctx;
\r
144 enum class ExprType
\r
146 Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier
\r
151 std::vector<std::string> namespacePrefixes;
\r
152 std::string functionName;
\r
153 std::vector<Expr> arguments;
\r
154 std::vector<Type> genericInstantiation;
\r
159 std::shared_ptr<Expr> expr;
\r
160 std::string methodName;
\r
161 std::vector<Expr> arguments;
\r
162 std::vector<Type> genericInstantiation;
\r
167 Int, Decimal, String, Bool
\r
176 std::string _string;
\r
182 std::shared_ptr<Expr> expr;
\r
188 std::shared_ptr<Expr> expr;
\r
189 std::string identifier;
\r
192 // OperatorType enum with corresponding string array to lookup
\r
193 // enum from string and the other way round
\r
194 enum class PrefixOperatorType
\r
196 Plus, Minus, Increment, Decrement,
\r
197 LogicalNot, BitwiseNot, Dereference, AddressOf,
\r
200 static std::string PrefixOperatorTypeStrings[] =
\r
202 "+", "-", "++", "--", "!", "~", "*", "&" };
\r
204 struct PrefixOperatorExpr
\r
206 PrefixOperatorType type;
\r
207 std::shared_ptr<Expr> expr;
\r
210 enum class PostfixOperatorType
\r
212 Increment, Decrement,
\r
215 static std::string PostfixOperatorTypeStrings[] =
\r
219 struct PostfixOperatorExpr
\r
221 PostfixOperatorType type;
\r
222 std::shared_ptr<Expr> expr;
\r
225 enum class BinaryOperatorType
\r
227 Plus, Minus, Multiply, Divide, Modulo, BitwiseAnd, BitwiseOr, BitwiseXor, LessThan, GreaterThan,
\r
228 LeftShift, RightShift, LogicalAnd, LogicalOr, Equals, NotEquals, LessThanEquals, GreaterThanEquals, BitwiseAndEquals, BitwiseOrEquals, BitwiseXorEquals,
\r
229 PlusEquals, MinusEquals, MultiplyEquals, DivideEquals, ModuloEquals,
\r
230 LeftShiftEquals, RightShiftEquals,
\r
233 static std::string BinaryOperatorTypeStrings[] =
\r
235 "+", "-", "*", "/", "%", "&", "|", "^", "<", ">",
\r
236 "<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=",
\r
237 "+=","-=","*=","/=","%=",
\r
240 struct BinaryOperatorExpr
\r
242 BinaryOperatorType type;
\r
243 std::shared_ptr<Expr> lexpr;
\r
244 std::shared_ptr<Expr> rexpr;
\r
247 struct TernaryOperatorExpr
\r
249 std::shared_ptr<Expr> lexpr;
\r
250 std::shared_ptr<Expr> rexprTrue;
\r
251 std::shared_ptr<Expr> rexprFalse;
\r
254 struct BracketsExpr
\r
256 std::shared_ptr<Expr> lexpr;
\r
257 std::shared_ptr<Expr> rexpr;
\r
260 struct IdentifierExpr
\r
262 std::vector<std::string> namespacePrefixes;
\r
263 std::string identifier;
\r
271 MethodExpr _method;
\r
275 PrefixOperatorExpr _prefixOp;
\r
276 PostfixOperatorExpr _postfixOp;
\r
277 BinaryOperatorExpr _binaryOp;
\r
278 TernaryOperatorExpr _ternaryOp;
\r
279 BracketsExpr _brackets;
\r
280 IdentifierExpr _identifier;
\r
283 enum class StmtType
\r
285 If, Switch, For, While, Assign, Return, Expr
\r
291 std::shared_ptr<Expr> expr;
\r
298 std::vector<ElseStmt> elses;
\r
303 std::shared_ptr<Expr> expr;
\r
309 std::shared_ptr<Expr> ident;
\r
310 std::vector<SwitchCase> cases;
\r
313 // TODO: int i = 0 (var decl)
\r
316 std::shared_ptr<AssignStmt> init;
\r
317 std::shared_ptr<Expr> condition;
\r
318 std::shared_ptr<Expr> action;
\r
343 SwitchStmt _switch;
\r
346 AssignStmt _assign;
\r
347 ReturnStmt _return;
\r