diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 06:02:21 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 06:02:21 +0000 |
| commit | 3425b95cb654f8e1adc98365a4b370aa1fff8b4d (patch) | |
| tree | 4d81b91d0bd807cd6f7ced037533d6e60f5c307f /include/cps/FunctionAST.h | |
| parent | 4e22f464387725a5a282f3d72e11cfb694a31a5a (diff) | |
feat(classes): support ordinary member methods and this references
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/FunctionAST.h')
| -rw-r--r-- | include/cps/FunctionAST.h | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/include/cps/FunctionAST.h b/include/cps/FunctionAST.h index 0c2d0b5..16057e5 100644 --- a/include/cps/FunctionAST.h +++ b/include/cps/FunctionAST.h @@ -28,18 +28,24 @@ class PrototypeAST { std::vector<ParamDecl> Params; std::string ReturnType; bool IsExternal; + std::string OwnerClass; + bool IsPublic; public: PrototypeAST(const std::string &Name, std::vector<ParamDecl> Params, const std::string &ReturnType, - bool IsExternal = false) - : Name(Name), Params(std::move(Params)), ReturnType(ReturnType), IsExternal(IsExternal) {} + bool IsExternal = false, std::string OwnerClass = {}, bool IsPublic = true) + : Name(Name), Params(std::move(Params)), ReturnType(ReturnType), IsExternal(IsExternal), + OwnerClass(std::move(OwnerClass)), IsPublic(IsPublic) {} const std::string &getName() const { return Name; } const std::vector<ParamDecl> &getParams() const { return Params; } const std::string &getReturnType() const { return ReturnType; } bool isExternal() const { return IsExternal; } + const std::string &getOwnerClass() const { return OwnerClass; } + bool isPublic() const { return IsPublic; } + std::string getLinkName() const { return OwnerClass.empty() ? Name : OwnerClass + "." + Name; } }; class FunctionDefAST : public StmtAST { @@ -80,6 +86,28 @@ public: }; +// A member call keeps the receiver separate from explicit arguments. +class MemberCallExprAST : public ExprAST { + std::unique_ptr<ExprAST> Receiver; + std::string Method; + std::vector<std::unique_ptr<ExprAST>> Args; +public: + MemberCallExprAST(std::unique_ptr<ExprAST> Receiver, std::string Method, + std::vector<std::unique_ptr<ExprAST>> Args, int Line) + : ExprAST(Line), Receiver(std::move(Receiver)), Method(std::move(Method)), Args(std::move(Args)) {} + ExprAST *getReceiver() const { return Receiver.get(); } + const std::string &getMethod() const { return Method; } + const std::vector<std::unique_ptr<ExprAST>> &getArgs() const { return Args; } +}; + +class MemberCallStmtAST : public StmtAST { + std::unique_ptr<MemberCallExprAST> Call; +public: + explicit MemberCallStmtAST(std::unique_ptr<MemberCallExprAST> Call) + : StmtAST(Call->getLine()), Call(std::move(Call)) {} + MemberCallExprAST *getCall() const { return Call.get(); } +}; + class ReturnStmtAST : public StmtAST { std::unique_ptr<ExprAST> RetVal; |
