From 3425b95cb654f8e1adc98365a4b370aa1fff8b4d Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 06:02:21 +0000 Subject: feat(classes): support ordinary member methods and this references Co-Authored-By: Claude Fable 5.1 --- include/cps/FunctionAST.h | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'include/cps/FunctionAST.h') 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 Params; std::string ReturnType; bool IsExternal; + std::string OwnerClass; + bool IsPublic; public: PrototypeAST(const std::string &Name, std::vector 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 &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 Receiver; + std::string Method; + std::vector> Args; +public: + MemberCallExprAST(std::unique_ptr Receiver, std::string Method, + std::vector> 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> &getArgs() const { return Args; } +}; + +class MemberCallStmtAST : public StmtAST { + std::unique_ptr Call; +public: + explicit MemberCallStmtAST(std::unique_ptr Call) + : StmtAST(Call->getLine()), Call(std::move(Call)) {} + MemberCallExprAST *getCall() const { return Call.get(); } +}; + class ReturnStmtAST : public StmtAST { std::unique_ptr RetVal; -- cgit v1.3.1-4-g156e