X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/71a20a4f3d4e5f5278f7d004af710af89dfd7ebc..c2ba7425955ae538e220cec79d9124756d1b4c8b:/src/repr.h diff --git a/src/repr.h b/src/repr.h index 47a78d7..f12b0da 100644 --- a/src/repr.h +++ b/src/repr.h @@ -13,18 +13,22 @@ struct Variable; struct Body; struct Function; struct Struct; +struct Namespace; struct Program; + struct FuncExpr; +struct MethodExpr; struct LitExpr; -struct IdentifierExpr; -struct AccessExpr; -struct BracketsExpr; -struct UnaryOperatorExpr; +struct ParenExpr; +struct DotExpr; +struct PrefixOperatorExpr; +struct PostfixOperatorExpr; struct BinaryOperatorExpr; struct TernaryOperatorExpr; -struct DotExpr; -struct ParenExpr; +struct BracketsExpr; +struct IdentifierExpr; struct Expr; + struct IfStmt; struct SwitchStmt; struct ForStmt; @@ -33,6 +37,12 @@ struct AssignStmt; struct ReturnStmt; struct Stmt; +struct Context +{ + std::shared_ptr parent; + std::vector variables; +}; + enum class TypeModifierType { Pointer, Array @@ -48,6 +58,7 @@ struct TypeModifier struct Type { + std::vector namespacePrefixes; std::string name; std::vector modifiers; }; @@ -60,7 +71,7 @@ struct Variable struct Body { - std::vector variables; + std::shared_ptr ctx; std::vector statements; }; @@ -69,34 +80,61 @@ struct Function Type returnType; std::string name; std::vector parameters; + bool defined; Body body; }; +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 Namespace +{ + std::string name; + std::shared_ptr ctx; + std::vector structs; + std::vector functions; + std::vector namespaces; }; struct Program { - std::vector variables; + std::shared_ptr ctx; std::vector structs; std::vector functions; + std::vector namespaces; }; enum class ExprType { - Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot + Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier }; struct FuncExpr { + std::vector namespacePrefixes; std::string functionName; std::vector arguments; }; +struct MethodExpr +{ + std::shared_ptr expr; + std::string methodName; + std::vector arguments; +}; + enum class LitType { Int, Decimal, String, Bool @@ -112,24 +150,47 @@ struct LitExpr bool _bool; }; -// TODO: accessExpr -struct IdentifierExpr +struct ParenExpr { - std::string name; + std::shared_ptr expr; }; -struct BracketsExpr +struct DotExpr { - std::shared_ptr lexpr; - std::shared_ptr rexpr; + std::shared_ptr expr; + std::string identifier; }; -enum class UnaryOperatorType +enum class PrefixOperatorType { - Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost, + Plus, Minus, Increment, Decrement, LogicalNot, BitwiseNot, Dereference, AddressOf, COUNT }; +static std::string PrefixOperatorTypeStrings[] = +{ + "+", "-", "++", "--", "!", "~", "*", "&" }; + +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 { @@ -139,10 +200,6 @@ enum class BinaryOperatorType LeftShiftEquals, RightShiftEquals, COUNT }; -static std::string UnaryOperatorTypeStrings[] = -{ - "+", "-", "++", "--", "++", "--", "!", "~", "*", "&" }; - static std::string BinaryOperatorTypeStrings[] = { "+", "-", "*", "/", "%", "&", "|", "^", "<", ">", @@ -150,12 +207,6 @@ static std::string BinaryOperatorTypeStrings[] = "+=","-=","*=","/=","%=", "<<=",">>=" }; -struct UnaryOperatorExpr -{ - UnaryOperatorType type; - std::shared_ptr expr; -}; - struct BinaryOperatorExpr { BinaryOperatorType type; @@ -170,27 +221,33 @@ struct TernaryOperatorExpr std::shared_ptr rexprFalse; }; -struct DotExpr +struct BracketsExpr { - std::shared_ptr expr; - IdentifierExpr ident; + std::shared_ptr lexpr; + std::shared_ptr rexpr; +}; + +struct IdentifierExpr +{ + std::vector namespacePrefixes; + std::string identifier; }; -// TODO: paren expr struct Expr { ExprType type; - bool parenthesized; - FuncExpr _func; + MethodExpr _method; LitExpr _lit; - IdentifierExpr _identifier; - BracketsExpr _brackets; - UnaryOperatorExpr _unaryOperator; - BinaryOperatorExpr _binaryOperator; - TernaryOperatorExpr _ternaryOperator; + ParenExpr _paren; DotExpr _dot; + PrefixOperatorExpr _prefixOp; + PostfixOperatorExpr _postfixOp; + BinaryOperatorExpr _binaryOp; + TernaryOperatorExpr _ternaryOp; + BracketsExpr _brackets; + IdentifierExpr _identifier; }; enum class StmtType @@ -219,15 +276,14 @@ struct SwitchCase struct SwitchStmt { - IdentifierExpr ident; + std::shared_ptr ident; std::vector cases; }; // TODO: int i = 0 (var decl) struct ForStmt { - std::string varName; - std::shared_ptr initValue; + std::shared_ptr init; std::shared_ptr condition; std::shared_ptr action; Body body; @@ -241,8 +297,7 @@ struct WhileStmt struct AssignStmt { - std::string name; - Expr expr; + Expr lexpr, rexpr; }; struct ReturnStmt