X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/45409c781a9e35df68c43b1e2f028d30bf90c0a0..dbc4a22d3c8c4189459f0361cb9da06415ec2dc9:/src/repr.h diff --git a/src/repr.h b/src/repr.h index ce176ef..f196427 100644 --- a/src/repr.h +++ b/src/repr.h @@ -13,143 +13,302 @@ struct Variable; struct Body; struct Function; struct Struct; +struct Namespace; struct Program; -struct CallExpr; -struct LiteralExpr; -struct VariableExpr; -struct BracketsExpr; -struct OperatorExpr; + +struct FuncExpr; +struct MethodExpr; +struct LitExpr; +struct ParenExpr; struct DotExpr; +struct PrefixOperatorExpr; +struct PostfixOperatorExpr; +struct BinaryOperatorExpr; +struct TernaryOperatorExpr; +struct BracketsExpr; +struct IdentifierExpr; struct Expr; + struct IfStmt; +struct SwitchStmt; +struct ForStmt; struct WhileStmt; -struct ReturnStmt; struct AssignStmt; +struct ReturnStmt; struct Stmt; +enum class TypeModifierType +{ + Pointer, Array +}; -struct Type { +struct TypeModifier +{ + TypeModifierType type; + + bool _staticArray; + int _arraySize; +}; + +struct Type +{ + std::vector namespacePrefixes; std::string name; + std::vector modifiers; }; -struct Variable { +struct Variable +{ std::string name; Type type; }; -struct Body { +struct Body +{ std::vector variables; std::vector statements; }; -struct Function { +struct Function +{ + Type returnType; std::string name; std::vector parameters; Body body; }; -struct Struct { +template +struct StructMember +{ + T t; + bool isPublic; + operator T() { return t; } +}; + +struct Struct +{ std::string name; - std::vector members; - std::vector methods; + std::vector> members; + std::vector> methods; }; -struct Program { +struct Namespace +{ + std::string name; std::vector variables; std::vector structs; std::vector functions; + std::vector namespaces; }; -enum class ExprType { - Call, Literal, Variable, Brackets, Operator, Dot +struct Program +{ + std::vector variables; + std::vector structs; + std::vector functions; + std::vector namespaces; +}; + +enum class ExprType +{ + Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier +}; + +struct FuncExpr +{ + std::vector namespacePrefixes; + std::string functionName; + std::vector arguments; }; -struct CallExpr { - Function function; +struct MethodExpr +{ + std::shared_ptr expr; + std::string methodName; std::vector arguments; }; -struct LiteralExpr { - int i; +enum class LitType +{ + Int, Decimal, String, Bool }; -struct VariableExpr { - std::string name; +struct LitExpr +{ + LitType type; + + int _int; + double _decimal; + std::string _string; + bool _bool; }; -struct BracketsExpr { - BracketsExpr() {} - BracketsExpr(const BracketsExpr &) {} - BracketsExpr & operator=(const BracketsExpr &) {return *this;}; - std::unique_ptr lexpr; - std::unique_ptr rexpr; +struct ParenExpr +{ + std::shared_ptr expr; }; -enum class OperatorType { - Plus, Minus, Multiply, Divide, - Equals, NotEquals, - LessThan, GreaterThan +struct DotExpr +{ + std::shared_ptr expr; + std::string identifier; }; -struct OperatorExpr { - OperatorExpr() {} - OperatorExpr(const OperatorExpr &) {} - OperatorExpr & operator=(const OperatorExpr &) {return *this;}; - std::unique_ptr lexpr; - std::unique_ptr rexpr; - OperatorType type; +enum class PrefixOperatorType +{ + Plus, Minus, Increment, Decrement, + LogicalNot, BitwiseNot, Dereference, AddressOf, + COUNT }; +static std::string PrefixOperatorTypeStrings[] = +{ + "+", "-", "++", "--", "!", "~", "*", "&" }; -struct DotExpr { - DotExpr() {} - DotExpr(const DotExpr &) {} - DotExpr & operator=(const DotExpr &) {return *this;}; - std::unique_ptr lexpr; - std::string name; +struct PrefixOperatorExpr +{ + PrefixOperatorType type; + std::shared_ptr expr; +}; + +enum class PostfixOperatorType +{ + Increment, Decrement, + COUNT +}; +static std::string PostfixOperatorTypeStrings[] = +{ + "++", "--" }; + +struct PostfixOperatorExpr +{ + PostfixOperatorType type; + std::shared_ptr expr; +}; + +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 BinaryOperatorTypeStrings[] = +{ + "+", "-", "*", "/", "%", "&", "|", "^", "<", ">", + "<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=", + "+=","-=","*=","/=","%=", + "<<=",">>=" }; + +struct BinaryOperatorExpr +{ + BinaryOperatorType type; + std::shared_ptr lexpr; + std::shared_ptr rexpr; +}; + +struct TernaryOperatorExpr +{ + std::shared_ptr lexpr; + std::shared_ptr rexprTrue; + std::shared_ptr rexprFalse; +}; + +struct BracketsExpr +{ + std::shared_ptr lexpr; + std::shared_ptr rexpr; +}; + +struct IdentifierExpr +{ + std::vector namespacePrefixes; + std::string identifier; }; -struct Expr { +struct Expr +{ ExprType type; - CallExpr _call; - LiteralExpr _literal; - VariableExpr _variable; - BracketsExpr _brackets; - OperatorExpr _operator; - DotExpr _dot; + FuncExpr _func; + MethodExpr _method; + LitExpr _lit; + ParenExpr _paren; + DotExpr _dot; + PrefixOperatorExpr _prefixOp; + PostfixOperatorExpr _postfixOp; + BinaryOperatorExpr _binaryOp; + TernaryOperatorExpr _ternaryOp; + BracketsExpr _brackets; + IdentifierExpr _identifier; }; -enum class StmtType { - If, While, Return, Assign, Expr +enum class StmtType +{ + If, Switch, For, While, Assign, Return, Expr }; -struct IfStmt { +struct ElseStmt +{ + bool _if; + std::shared_ptr expr; + Body body; +}; +struct IfStmt +{ Expr condition; Body body; + std::vector elses; +}; + +struct SwitchCase +{ + std::shared_ptr expr; + Body body; +}; + +struct SwitchStmt +{ + std::shared_ptr ident; + std::vector cases; +}; + +// TODO: int i = 0 (var decl) +struct ForStmt +{ + std::shared_ptr init; + std::shared_ptr condition; + std::shared_ptr action; + Body body; }; -struct WhileStmt { +struct WhileStmt +{ Expr condition; Body body; }; -struct ReturnStmt { - Expr expr; +struct AssignStmt +{ + Expr lexpr, rexpr; }; -struct AssignStmt { - Expr lexpr; - Expr rexpr; +struct ReturnStmt +{ + Expr expr; }; -struct Stmt { +struct Stmt +{ StmtType type; - IfStmt _if; - WhileStmt _while; - ReturnStmt _return; - AssignStmt _assign; - Expr _expr; + IfStmt _if; + SwitchStmt _switch; + ForStmt _for; + WhileStmt _while; + AssignStmt _assign; + ReturnStmt _return; + Expr _expr; };