struct Body;\r
struct Function;\r
struct Struct;\r
+struct Namespace;\r
struct Program;\r
+\r
struct FuncExpr;\r
+struct MethodExpr;\r
struct LitExpr;\r
-struct IdentifierExpr;\r
-struct AccessExpr;\r
-struct BracketsExpr;\r
-struct UnaryOperatorExpr;\r
+struct ParenExpr;\r
+struct DotExpr;\r
+struct PrefixOperatorExpr;\r
+struct PostfixOperatorExpr;\r
struct BinaryOperatorExpr;\r
struct TernaryOperatorExpr;\r
-struct DotExpr;\r
-struct ParenExpr;\r
+struct BracketsExpr;\r
+struct IdentifierExpr;\r
struct Expr;\r
+\r
struct IfStmt;\r
struct SwitchStmt;\r
struct ForStmt;\r
struct ReturnStmt;\r
struct Stmt;\r
\r
-enum class TypeModifierType {\r
+struct Context\r
+{\r
+ std::shared_ptr<Context> parent;\r
+ std::vector<Variable> variables;\r
+};\r
+\r
+enum class TypeModifierType\r
+{\r
Pointer, Array\r
};\r
\r
-struct TypeModifier {\r
+struct TypeModifier\r
+{\r
TypeModifierType type;\r
\r
bool _staticArray;\r
int _arraySize;\r
};\r
\r
-struct Type {\r
+struct Type\r
+{\r
+ std::vector<std::string> namespacePrefixes;\r
std::string name;\r
std::vector<TypeModifier> modifiers;\r
+ std::vector<Type> genericInstantiation;\r
};\r
\r
-struct Variable {\r
+struct Variable\r
+{\r
std::string name;\r
Type type;\r
};\r
\r
-struct Body {\r
- std::vector<Variable> variables;\r
+struct Body\r
+{\r
+ std::shared_ptr<Context> ctx;\r
std::vector<Stmt> statements;\r
};\r
\r
-struct Function {\r
- Type returnType;\r
+struct Function\r
+{\r
std::string name;\r
+ std::vector<std::string> genericTypeNames;\r
+ std::vector<std::vector<Type>> genericInstantiations;\r
+ Type returnType;\r
std::vector<Variable> parameters;\r
+ bool defined;\r
Body body;\r
};\r
\r
-struct Struct {\r
+template<typename T>\r
+struct StructMember\r
+{\r
+ T t;\r
+ bool isPublic;\r
+ operator T() { return t; }\r
+};\r
+\r
+struct Struct\r
+{\r
std::string name;\r
- std::vector<Variable> members;\r
- std::vector<Function> methods;\r
+ std::vector<std::string> genericTypeNames;\r
+ std::vector<std::vector<Type>> genericInstantiations;\r
+ std::vector<StructMember<Variable>> members;\r
+ std::vector<StructMember<Function>> methods;\r
};\r
\r
-struct Program {\r
- std::vector<Variable> variables;\r
+struct Namespace\r
+{\r
+ std::string name;\r
+ std::shared_ptr<Context> ctx;\r
+ std::vector<Struct> structs;\r
+ std::vector<Function> functions;\r
+ std::vector<Namespace> namespaces;\r
+};\r
+\r
+struct Program\r
+{\r
+ std::shared_ptr<Context> ctx;\r
std::vector<Struct> structs;\r
std::vector<Function> functions;\r
+ std::vector<Namespace> namespaces;\r
};\r
\r
-enum class ExprType {\r
- Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot\r
+enum class ExprType\r
+{\r
+ Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier\r
};\r
\r
-struct FuncExpr {\r
+struct FuncExpr\r
+{\r
+ std::vector<std::string> namespacePrefixes;\r
std::string functionName;\r
std::vector<Expr> arguments;\r
+ std::vector<Type> genericInstantiation;\r
};\r
\r
-enum class LitType {\r
+struct MethodExpr\r
+{\r
+ std::shared_ptr<Expr> expr;\r
+ std::string methodName;\r
+ std::vector<Expr> arguments;\r
+ std::vector<Type> genericInstantiation;\r
+};\r
+\r
+enum class LitType\r
+{\r
Int, Decimal, String, Bool\r
};\r
\r
-struct LitExpr {\r
+struct LitExpr\r
+{\r
LitType type;\r
\r
int _int;\r
bool _bool;\r
};\r
\r
-// TODO: accessExpr\r
-struct IdentifierExpr {\r
- std::string name;\r
+struct ParenExpr\r
+{\r
+ std::shared_ptr<Expr> expr;\r
};\r
\r
-struct BracketsExpr {\r
- std::shared_ptr<Expr> lexpr;\r
- std::shared_ptr<Expr> rexpr;\r
+struct DotExpr\r
+{\r
+ bool isPointer;\r
+ std::shared_ptr<Expr> expr;\r
+ std::string identifier;\r
};\r
\r
-enum class UnaryOperatorType {\r
- Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost,\r
+enum class PrefixOperatorType\r
+{\r
+ Plus, Minus, Increment, Decrement,\r
LogicalNot, BitwiseNot, Dereference, AddressOf,\r
COUNT\r
};\r
+static std::string PrefixOperatorTypeStrings[] =\r
+{\r
+ "+", "-", "++", "--", "!", "~", "*", "&" };\r
\r
-enum class BinaryOperatorType {\r
+struct PrefixOperatorExpr\r
+{\r
+ PrefixOperatorType type;\r
+ std::shared_ptr<Expr> expr;\r
+};\r
+\r
+enum class PostfixOperatorType\r
+{\r
+ Increment, Decrement,\r
+ COUNT\r
+};\r
+static std::string PostfixOperatorTypeStrings[] =\r
+{\r
+ "++", "--" };\r
+\r
+struct PostfixOperatorExpr\r
+{\r
+ PostfixOperatorType type;\r
+ std::shared_ptr<Expr> expr;\r
+};\r
+\r
+enum class BinaryOperatorType\r
+{\r
Plus, Minus, Multiply, Divide, Modulo, BitwiseAnd, BitwiseOr, BitwiseXor, LessThan, GreaterThan,\r
LeftShift, RightShift, LogicalAnd, LogicalOr, Equals, NotEquals, LessThanEquals, GreaterThanEquals, BitwiseAndEquals, BitwiseOrEquals, BitwiseXorEquals,\r
PlusEquals, MinusEquals, MultiplyEquals, DivideEquals, ModuloEquals,\r
LeftShiftEquals, RightShiftEquals,\r
COUNT\r
};\r
-static std::string UnaryOperatorTypeStrings[] = {\r
- "+", "-", "++", "--", "++", "--", "!", "~", "*", "&" };\r
-\r
-static std::string BinaryOperatorTypeStrings[] = {\r
+static std::string BinaryOperatorTypeStrings[] =\r
+{\r
"+", "-", "*", "/", "%", "&", "|", "^", "<", ">",\r
"<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=",\r
"+=","-=","*=","/=","%=",\r
"<<=",">>=" };\r
\r
-struct UnaryOperatorExpr {\r
- UnaryOperatorType type;\r
- std::shared_ptr<Expr> expr;\r
-};\r
-\r
-struct BinaryOperatorExpr {\r
+struct BinaryOperatorExpr\r
+{\r
BinaryOperatorType type;\r
std::shared_ptr<Expr> lexpr;\r
std::shared_ptr<Expr> rexpr;\r
};\r
\r
-struct TernaryOperatorExpr {\r
+struct TernaryOperatorExpr\r
+{\r
std::shared_ptr<Expr> lexpr;\r
std::shared_ptr<Expr> rexprTrue;\r
std::shared_ptr<Expr> rexprFalse;\r
};\r
\r
-struct DotExpr {\r
- std::shared_ptr<Expr> expr;\r
- IdentifierExpr ident;\r
+struct BracketsExpr\r
+{\r
+ std::shared_ptr<Expr> lexpr;\r
+ std::shared_ptr<Expr> rexpr;\r
};\r
\r
-// TODO: paren expr\r
-struct Expr {\r
- ExprType type;\r
+struct IdentifierExpr\r
+{\r
+ std::vector<std::string> namespacePrefixes;\r
+ std::string identifier;\r
+};\r
\r
- bool parenthesized;\r
+struct Expr\r
+{\r
+ ExprType type;\r
\r
FuncExpr _func;\r
+ MethodExpr _method;\r
LitExpr _lit;\r
- IdentifierExpr _identifier;\r
- BracketsExpr _brackets;\r
- UnaryOperatorExpr _unaryOperator;\r
- BinaryOperatorExpr _binaryOperator;\r
- TernaryOperatorExpr _ternaryOperator;\r
+ ParenExpr _paren;\r
DotExpr _dot;\r
+ PrefixOperatorExpr _prefixOp;\r
+ PostfixOperatorExpr _postfixOp;\r
+ BinaryOperatorExpr _binaryOp;\r
+ TernaryOperatorExpr _ternaryOp;\r
+ BracketsExpr _brackets;\r
+ IdentifierExpr _identifier;\r
};\r
\r
-enum class StmtType {\r
+enum class StmtType\r
+{\r
If, Switch, For, While, Assign, Return, Expr\r
};\r
\r
-struct ElseStmt {\r
+struct ElseStmt\r
+{\r
bool _if;\r
std::shared_ptr<Expr> expr;\r
Body body;\r
};\r
-struct IfStmt {\r
+struct IfStmt\r
+{\r
Expr condition;\r
Body body;\r
std::vector<ElseStmt> elses;\r
};\r
\r
-struct SwitchCase {\r
+struct SwitchCase\r
+{\r
std::shared_ptr<Expr> expr;\r
Body body;\r
};\r
\r
-struct SwitchStmt {\r
- IdentifierExpr ident;\r
+struct SwitchStmt\r
+{\r
+ std::shared_ptr<Expr> ident;\r
std::vector<SwitchCase> cases;\r
};\r
\r
// TODO: int i = 0 (var decl)\r
-struct ForStmt {\r
- std::string varName;\r
- std::shared_ptr<Expr> initValue;\r
+struct ForStmt\r
+{\r
+ std::shared_ptr<AssignStmt> init;\r
std::shared_ptr<Expr> condition;\r
std::shared_ptr<Expr> action;\r
Body body;\r
};\r
\r
-struct WhileStmt {\r
+struct WhileStmt\r
+{\r
Expr condition;\r
Body body;\r
};\r
\r
-struct AssignStmt {\r
- std::string name;\r
- Expr expr;\r
+struct AssignStmt\r
+{\r
+ Expr lexpr, rexpr;\r
};\r
\r
-struct ReturnStmt {\r
+struct ReturnStmt\r
+{\r
Expr expr;\r
};\r
\r
-struct Stmt {\r
+struct Stmt\r
+{\r
StmtType type;\r
\r
IfStmt _if;\r