aboutsummaryrefslogtreecommitdiff
path: root/include/cps/FunctionAST.h
blob: 5b4da6c95477c74b64c53d9c2cbb17e51551f932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

#pragma once
#include "cps/AST.h"
#include <vector>
#include <string>
#include <memory>
#include <tuple>

namespace cps {

class PrototypeAST {
    std::string Name;
    std::vector<std::tuple<std::string, std::string, bool>> Args;
    std::string ReturnType;
    bool IsExternal;

public:
    PrototypeAST(const std::string &Name, 
                 std::vector<std::tuple<std::string, std::string, bool>> 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::tuple<std::string, std::string, bool>> &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