|
| 1 | +#ifndef PARSER_BUILDERASTFACTORY_HPP_ |
| 2 | +#define PARSER_BUILDERASTFACTORY_HPP_ |
| 3 | + |
| 4 | +#include <memory> |
| 5 | +#include <optional> |
| 6 | +#include <string> |
| 7 | +#include <vector> |
| 8 | + |
| 9 | +#include "IAstFactory.hpp" |
| 10 | + |
| 11 | +namespace ovum::compiler::parser { |
| 12 | + |
| 13 | +class BuilderAstFactory : public IAstFactory { |
| 14 | +public: |
| 15 | + ~BuilderAstFactory() override = default; |
| 16 | + |
| 17 | + // Module / Decls |
| 18 | + std::unique_ptr<Module> MakeModule(std::string name, |
| 19 | + SourceId source_id, |
| 20 | + std::vector<std::unique_ptr<Decl>> decls, |
| 21 | + SourceSpan span) override; |
| 22 | + |
| 23 | + std::unique_ptr<FunctionDecl> MakeFunction(bool is_pure, |
| 24 | + std::string name, |
| 25 | + std::vector<Param> params, |
| 26 | + std::unique_ptr<TypeReference> return_type, |
| 27 | + std::unique_ptr<Block> body, |
| 28 | + SourceSpan span) override; |
| 29 | + |
| 30 | + std::unique_ptr<ClassDecl> MakeClass(std::string name, |
| 31 | + std::vector<TypeReference> implements, |
| 32 | + std::vector<std::unique_ptr<Decl>> members, |
| 33 | + SourceSpan span) override; |
| 34 | + |
| 35 | + std::unique_ptr<InterfaceDecl> MakeInterface(std::string name, |
| 36 | + std::vector<std::unique_ptr<InterfaceMethod>> methods, |
| 37 | + SourceSpan span) override; |
| 38 | + |
| 39 | + std::unique_ptr<InterfaceMethod> MakeInterfaceMethod(std::string name, |
| 40 | + std::vector<InterfaceMethod::Param> params, |
| 41 | + std::unique_ptr<TypeReference> return_type, |
| 42 | + SourceSpan span) override; |
| 43 | + |
| 44 | + std::unique_ptr<TypeAliasDecl> MakeTypeAlias(std::string name, TypeReference aliased_type, SourceSpan span) override; |
| 45 | + |
| 46 | + std::unique_ptr<GlobalVarDecl> MakeGlobalVar( |
| 47 | + bool is_var, std::string name, TypeReference type, std::unique_ptr<Expr> init, SourceSpan span) override; |
| 48 | + |
| 49 | + // Class members |
| 50 | + std::unique_ptr<FieldDecl> MakeField(bool is_public, |
| 51 | + bool is_var, |
| 52 | + std::string name, |
| 53 | + TypeReference type, |
| 54 | + std::unique_ptr<Expr> init, |
| 55 | + SourceSpan span) override; |
| 56 | + |
| 57 | + std::unique_ptr<StaticFieldDecl> MakeStaticField(bool is_public, |
| 58 | + bool is_var, |
| 59 | + std::string name, |
| 60 | + TypeReference type, |
| 61 | + std::unique_ptr<Expr> init, |
| 62 | + SourceSpan span) override; |
| 63 | + |
| 64 | + std::unique_ptr<MethodDecl> MakeMethod(bool is_public, |
| 65 | + bool is_override, |
| 66 | + bool is_static, |
| 67 | + bool is_pure, |
| 68 | + std::string name, |
| 69 | + std::vector<Param> params, |
| 70 | + std::unique_ptr<TypeReference> ret_type, |
| 71 | + std::unique_ptr<Block> body, |
| 72 | + SourceSpan span) override; |
| 73 | + |
| 74 | + std::unique_ptr<CallDecl> MakeCallDecl(bool is_public, |
| 75 | + std::vector<Param> params, |
| 76 | + std::unique_ptr<TypeReference> ret_type, |
| 77 | + std::unique_ptr<Block> body, |
| 78 | + SourceSpan span) override; |
| 79 | + |
| 80 | + std::unique_ptr<DestructorDecl> MakeDestructor(bool is_public, std::unique_ptr<Block> body, SourceSpan span) override; |
| 81 | + |
| 82 | + // Statements |
| 83 | + std::unique_ptr<Block> MakeBlock(std::vector<std::unique_ptr<Stmt>> stmts, SourceSpan span) override; |
| 84 | + |
| 85 | + std::unique_ptr<VarDeclStmt> MakeVarDeclStmt( |
| 86 | + bool is_var, std::string name, TypeReference type, std::unique_ptr<Expr> init, SourceSpan span) override; |
| 87 | + |
| 88 | + std::unique_ptr<ExprStmt> MakeExprStmt(std::unique_ptr<Expr> expr, SourceSpan span) override; |
| 89 | + |
| 90 | + std::unique_ptr<ReturnStmt> MakeReturnStmt(std::unique_ptr<Expr> value, SourceSpan span) override; |
| 91 | + |
| 92 | + std::unique_ptr<BreakStmt> MakeBreakStmt(SourceSpan span) override; |
| 93 | + std::unique_ptr<ContinueStmt> MakeContinueStmt(SourceSpan span) override; |
| 94 | + |
| 95 | + std::unique_ptr<IfStmt> MakeIfStmt(std::vector<Branch> branches, |
| 96 | + std::unique_ptr<Block> else_block, |
| 97 | + SourceSpan span) override; |
| 98 | + |
| 99 | + std::unique_ptr<WhileStmt> MakeWhileStmt(std::unique_ptr<Expr> cond, |
| 100 | + std::unique_ptr<Block> body, |
| 101 | + SourceSpan span) override; |
| 102 | + |
| 103 | + std::unique_ptr<ForStmt> MakeForStmt(std::string iter_name, |
| 104 | + std::unique_ptr<Expr> iter_expr, |
| 105 | + std::unique_ptr<Block> body, |
| 106 | + SourceSpan span) override; |
| 107 | + |
| 108 | + std::unique_ptr<UnsafeBlock> MakeUnsafeBlock(std::unique_ptr<Block> body, SourceSpan span) override; |
| 109 | + |
| 110 | + // Expressions |
| 111 | + std::unique_ptr<Binary> MakeBinary(const IBinaryOpTag& op, |
| 112 | + std::unique_ptr<Expr> lhs, |
| 113 | + std::unique_ptr<Expr> rhs, |
| 114 | + SourceSpan span) override; |
| 115 | + |
| 116 | + std::unique_ptr<Unary> MakeUnary(const IUnaryOpTag& op, std::unique_ptr<Expr> operand, SourceSpan span) override; |
| 117 | + |
| 118 | + std::unique_ptr<Assign> MakeAssign(const IAssignOpTag& op, |
| 119 | + std::unique_ptr<Expr> target, |
| 120 | + std::unique_ptr<Expr> value, |
| 121 | + SourceSpan span) override; |
| 122 | + |
| 123 | + std::unique_ptr<Call> MakeCall(std::unique_ptr<Expr> callee, |
| 124 | + std::vector<std::unique_ptr<Expr>> args, |
| 125 | + SourceSpan span) override; |
| 126 | + |
| 127 | + std::unique_ptr<FieldAccess> MakeFieldAccess(std::unique_ptr<Expr> object, |
| 128 | + std::string name, |
| 129 | + SourceSpan span) override; |
| 130 | + |
| 131 | + std::unique_ptr<IndexAccess> MakeIndexAccess(std::unique_ptr<Expr> object, |
| 132 | + std::unique_ptr<Expr> index, |
| 133 | + SourceSpan span) override; |
| 134 | + |
| 135 | + std::unique_ptr<NamespaceRef> MakeNamespaceRef(std::unique_ptr<Expr> ns, std::string name, SourceSpan span) override; |
| 136 | + |
| 137 | + std::unique_ptr<SafeCall> MakeSafeCall(std::unique_ptr<Expr> object, |
| 138 | + std::string method, |
| 139 | + std::vector<std::unique_ptr<Expr>> args, |
| 140 | + std::optional<TypeReference> inferred_type, |
| 141 | + SourceSpan span) override; |
| 142 | + |
| 143 | + std::unique_ptr<Elvis> MakeElvis(std::unique_ptr<Expr> lhs, std::unique_ptr<Expr> rhs, SourceSpan span) override; |
| 144 | + |
| 145 | + std::unique_ptr<CastAs> MakeCastAs(std::unique_ptr<Expr> expr, TypeReference type, SourceSpan span) override; |
| 146 | + |
| 147 | + std::unique_ptr<TypeTestIs> MakeTypeTestIs(std::unique_ptr<Expr> expr, TypeReference type, SourceSpan span) override; |
| 148 | + |
| 149 | + std::unique_ptr<IdentRef> MakeIdent(std::string name, SourceSpan span) override; |
| 150 | + std::unique_ptr<IntLit> MakeInt(long long v, SourceSpan span) override; |
| 151 | + std::unique_ptr<FloatLit> MakeFloat(long double v, SourceSpan span) override; |
| 152 | + std::unique_ptr<StringLit> MakeString(std::string v, SourceSpan span) override; |
| 153 | + std::unique_ptr<CharLit> MakeChar(char v, SourceSpan span) override; |
| 154 | + std::unique_ptr<BoolLit> MakeBool(bool v, SourceSpan span) override; |
| 155 | + std::unique_ptr<NullLit> MakeNull(SourceSpan span) override; |
| 156 | +}; |
| 157 | + |
| 158 | +} // namespace ovum::compiler::parser |
| 159 | + |
| 160 | +#endif // PARSER_BUILDERASTFACTORY_HPP_ |
0 commit comments