diff options
| author | _ov4 <hausemasterstream@gmail.com> | 2026-01-30 13:11:20 +0000 |
|---|---|---|
| committer | _ov4 <hausemasterstream@gmail.com> | 2026-01-30 13:11:20 +0000 |
| commit | bd799e42b40613983c6e3cb9aedf58866ac68605 (patch) | |
| tree | 03fdd0dffba45fa2a1d9b8d4b0e78f49140c07e5 /include/cps/FunctionAST.h | |
| parent | 80420b0f92f42edc0a3cac4490a08adb8b2457dc (diff) | |
Added FUNCTION and PROCEDURE
Diffstat (limited to 'include/cps/FunctionAST.h')
| -rw-r--r-- | include/cps/FunctionAST.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/include/cps/FunctionAST.h b/include/cps/FunctionAST.h new file mode 100644 index 0000000..155bd8c --- /dev/null +++ b/include/cps/FunctionAST.h @@ -0,0 +1,76 @@ +#pragma once +#include "cps/AST.h" +#include <vector> +#include <string> +#include <memory> + +namespace cps { + +class PrototypeAST { + std::string Name; + std::vector<std::pair<std::string, std::string>> Args; + std::string ReturnType; + bool IsExternal; + +public: + PrototypeAST(const std::string &Name, + std::vector<std::pair<std::string, std::string>> Args, + const std::string &ReturnType, + bool IsExternal = false) + : Name(Name), Args(std::move(Args)), ReturnType(ReturnType), IsExternal(IsExternal) {} + + const std::string &getName() const { return Name; } + const std::vector<std::pair<std::string, std::string>> &getArgs() const { return Args; } + const std::string &getReturnType() const { return ReturnType; } + bool isExternal() const { return IsExternal; } +}; + +class FunctionDefAST : public StmtAST { + std::unique_ptr<PrototypeAST> Proto; + std::vector<std::unique_ptr<StmtAST>> Body; + +public: + FunctionDefAST(std::unique_ptr<PrototypeAST> Proto, + std::vector<std::unique_ptr<StmtAST>> Body) + : Proto(std::move(Proto)), Body(std::move(Body)) {} + + PrototypeAST *getProto() const { return Proto.get(); } + const std::vector<std::unique_ptr<StmtAST>> &getBody() const { return Body; } +}; + +class CallExprAST : public ExprAST { + std::string Callee; + std::vector<std::unique_ptr<ExprAST>> Args; + +public: + CallExprAST(const std::string &Callee, std::vector<std::unique_ptr<ExprAST>> Args) + : Callee(Callee), Args(std::move(Args)) {} + + const std::string &getCallee() const { return Callee; } + const std::vector<std::unique_ptr<ExprAST>> &getArgs() const { return Args; } +}; + +class CallStmtAST : public StmtAST { + std::string Callee; + std::vector<std::unique_ptr<ExprAST>> Args; + +public: + CallStmtAST(const std::string &Callee, std::vector<std::unique_ptr<ExprAST>> Args) + : Callee(Callee), Args(std::move(Args)) {} + + const std::string &getCallee() const { return Callee; } + const std::vector<std::unique_ptr<ExprAST>> &getArgs() const { return Args; } +}; + + +class ReturnStmtAST : public StmtAST { + std::unique_ptr<ExprAST> RetVal; + +public: + ReturnStmtAST(std::unique_ptr<ExprAST> RetVal = nullptr) + : RetVal(std::move(RetVal)) {} + + ExprAST *getRetVal() const { return RetVal.get(); } +}; + +} // namespace cps |
