]> gitweb.ps.run Git - toc/blobdiff - src/repr.h
generic functions and structs
[toc] / src / repr.h
index 47a78d7f795bc0be4e75edf13b5e175c8f3639e7..b30aecd1a8f15aa1fc9c827804ef6c01693856e8 100644 (file)
@@ -13,18 +13,22 @@ struct Variable;
 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
@@ -33,6 +37,12 @@ struct AssignStmt;
 struct ReturnStmt;\r
 struct Stmt;\r
 \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
@@ -48,8 +58,10 @@ struct TypeModifier
 \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
@@ -60,41 +72,74 @@ struct Variable
 \r
 struct Body\r
 {\r
-  std::vector<Variable> variables;\r
+  std::shared_ptr<Context> ctx;\r
   std::vector<Stmt> statements;\r
 };\r
 \r
 struct Function\r
 {\r
-  Type returnType;\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
+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 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::vector<Variable> variables;\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
 {\r
-  Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot\r
+  Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier\r
 };\r
 \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
+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
@@ -112,24 +157,48 @@ struct LitExpr
   bool _bool;\r
 };\r
 \r
-// TODO: accessExpr\r
-struct IdentifierExpr\r
+struct ParenExpr\r
 {\r
-  std::string name;\r
+  std::shared_ptr<Expr> expr;\r
 };\r
 \r
-struct BracketsExpr\r
+struct DotExpr\r
 {\r
-  std::shared_ptr<Expr> lexpr;\r
-  std::shared_ptr<Expr> rexpr;\r
+  bool isPointer;\r
+  std::shared_ptr<Expr> expr;\r
+  std::string identifier;\r
 };\r
 \r
-enum class UnaryOperatorType\r
+enum class PrefixOperatorType\r
 {\r
-  Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost,\r
+  Plus, Minus, Increment, Decrement,\r
   LogicalNot, BitwiseNot, Dereference, AddressOf,\r
   COUNT\r
 };\r
+static std::string PrefixOperatorTypeStrings[] =\r
+{\r
+  "+", "-", "++", "--", "!", "~", "*", "&" };\r
+\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
@@ -139,10 +208,6 @@ enum class BinaryOperatorType
   LeftShiftEquals, RightShiftEquals,\r
   COUNT\r
 };\r
-static std::string UnaryOperatorTypeStrings[] =\r
-{\r
-  "+", "-", "++", "--", "++", "--", "!", "~", "*", "&" };\r
-\r
 static std::string BinaryOperatorTypeStrings[] =\r
 {\r
   "+", "-", "*", "/", "%", "&", "|", "^", "<", ">",\r
@@ -150,12 +215,6 @@ static std::string BinaryOperatorTypeStrings[] =
   "+=","-=","*=","/=","%=",\r
   "<<=",">>=" };\r
 \r
-struct UnaryOperatorExpr\r
-{\r
-  UnaryOperatorType type;\r
-  std::shared_ptr<Expr> expr;\r
-};\r
-\r
 struct BinaryOperatorExpr\r
 {\r
   BinaryOperatorType type;\r
@@ -170,27 +229,33 @@ struct TernaryOperatorExpr
   std::shared_ptr<Expr> rexprFalse;\r
 };\r
 \r
-struct DotExpr\r
+struct BracketsExpr\r
 {\r
-  std::shared_ptr<Expr> expr;\r
-  IdentifierExpr ident;\r
+  std::shared_ptr<Expr> lexpr;\r
+  std::shared_ptr<Expr> rexpr;\r
+};\r
+\r
+struct IdentifierExpr\r
+{\r
+  std::vector<std::string> namespacePrefixes;\r
+  std::string identifier;\r
 };\r
 \r
-// TODO: paren expr\r
 struct Expr\r
 {\r
   ExprType type;\r
 \r
-  bool parenthesized;\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
@@ -219,15 +284,14 @@ struct SwitchCase
 \r
 struct SwitchStmt\r
 {\r
-  IdentifierExpr ident;\r
+  std::shared_ptr<Expr> ident;\r
   std::vector<SwitchCase> cases;\r
 };\r
 \r
 // TODO: int i = 0 (var decl)\r
 struct ForStmt\r
 {\r
-  std::string varName;\r
-  std::shared_ptr<Expr> initValue;\r
+  std::shared_ptr<AssignStmt> init;\r
   std::shared_ptr<Expr> condition;\r
   std::shared_ptr<Expr> action;\r
   Body body;\r
@@ -241,8 +305,7 @@ struct WhileStmt
 \r
 struct AssignStmt\r
 {\r
-  std::string name;\r
-  Expr expr;\r
+  Expr lexpr, rexpr;\r
 };\r
 \r
 struct ReturnStmt\r