#pragma once #include "cps/AST.h" #include #include #include #include #include namespace cps { enum class PassMode : uint8_t { ByVal, ByRef }; // One declared FUNCTION/PROCEDURE parameter. For array parameters TypeName // is the ELEMENT type; DeclaredBounds holds literal per-dimension bounds for // the bounded form (empty for `ARRAY OF T`, which is rank 1 with the bounds // travelling alongside the argument). struct ParamDecl { std::string Name; std::string TypeName; PassMode Mode = PassMode::ByVal; bool IsArray = false; int Rank = 0; // 0 = scalar std::vector> DeclaredBounds; }; class PrototypeAST { std::string Name; std::vector Params; std::string ReturnType; bool IsExternal; 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) {} 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; } }; class FunctionDefAST : public StmtAST { std::unique_ptr Proto; std::vector> Body; public: FunctionDefAST(std::unique_ptr Proto, std::vector> Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} PrototypeAST *getProto() const { return Proto.get(); } const std::vector> &getBody() const { return Body; } }; class CallExprAST : public ExprAST { std::string Callee; std::vector> Args; int Line; public: CallExprAST(const std::string &Callee, std::vector> Args, int Line) : Callee(Callee), Args(std::move(Args)), Line(Line) {} const std::string &getCallee() const { return Callee; } const std::vector> &getArgs() const { return Args; } int getLine() const { return Line; } }; class CallStmtAST : public StmtAST { std::string Callee; std::vector> Args; int Line; public: CallStmtAST(const std::string &Callee, std::vector> Args, int Line) : Callee(Callee), Args(std::move(Args)), Line(Line) {} const std::string &getCallee() const { return Callee; } const std::vector> &getArgs() const { return Args; } int getLine() const { return Line; } }; class ReturnStmtAST : public StmtAST { std::unique_ptr RetVal; public: ReturnStmtAST(std::unique_ptr RetVal = nullptr) : RetVal(std::move(RetVal)) {} ExprAST *getRetVal() const { return RetVal.get(); } }; } // namespace cps