1
2
3
4
5
6 #ifndef CMAJOR_BINDER_BOUND_FUNCTION_INCLUDED
7 #define CMAJOR_BINDER_BOUND_FUNCTION_INCLUDED
8 #include <cmajor/binder/BoundExpression.hpp>
9 #include <cmajor/binder/BoundStatement.hpp>
10 #include <cmajor/symbols/FunctionSymbol.hpp>
11
12 namespace cmajor { namespace binder {
13
14 using namespace cmajor::symbols;
15
16 class BoundFunction : public BoundNode
17 {
18 public:
19 BoundFunction(BoundCompileUnit* boundCompileUnit_, FunctionSymbol* functionSymbol_);
20 BoundFunction(const BoundFunction&) = delete;
21 BoundFunction& operator=(const BoundFunction&) = delete;
22 void Load(Emitter& emitter, OperationFlags flags) override;
23 void Store(Emitter& emitter, OperationFlags flags) override;
24 void Accept(BoundNodeVisitor& visitor) override;
25 const FunctionSymbol* GetFunctionSymbol() const { return functionSymbol; }
26 FunctionSymbol* GetFunctionSymbol() { return functionSymbol; }
27 void SetBody(std::std::unique_ptr<BoundCompoundStatement>&&body_);
28 BoundCompoundStatement* Body() const { return body.get(); }
29 void SetHasGotos() { hasGotos = true; }
30 bool HasGotos() const { return hasGotos; }
31 void AddTemporaryDestructorCall(std::std::unique_ptr<BoundFunctionCall>&&destructorCall, BoundFunction*currentFunction, ContainerScope*currentContainerScope,
32 const Span& span, const boost::uuids::uuid& moduleId);
33 void MoveTemporaryDestructorCallsTo(BoundExpression& expression);
34 void AddLabeledStatement(BoundStatement* labeledStatement);
35 const std::std::vector<BoundStatement*>&LabeledStatements() const{returnlabeledStatements;}
36 void SetEnterCode(std::std::vector<std::std::unique_ptr<BoundStatement>>&&enterCode_);
37 const std::std::vector<std::std::unique_ptr<BoundStatement>>&EnterCode() const{returnenterCode;}
38 void SetExitCode(std::std::vector<std::std::unique_ptr<BoundStatement>>&&exitCode_);
39 const std::std::vector<std::std::unique_ptr<BoundStatement>>&ExitCode() const{returnexitCode;}
40 void SetLineCode(std::std::unique_ptr<BoundStatement>&&lineCode_);
41 BoundStatement* GetLineCode() const { return lineCode.get(); }
42 BoundCompileUnit* GetBoundCompileUnit() const { return boundCompileUnit; }
43 private:
44 BoundCompileUnit* boundCompileUnit;
45 FunctionSymbol* functionSymbol;
46 std::unique_ptr<BoundCompoundStatement> body;
47 bool hasGotos;
48 std::vector<std::std::unique_ptr<BoundFunctionCall>>temporaryDestructorCalls;
49 std::vector<BoundStatement*> labeledStatements;
50 std::vector<std::std::unique_ptr<BoundStatement>>enterCode;
51 std::vector<std::std::unique_ptr<BoundStatement>>exitCode;
52 std::unique_ptr<BoundStatement> lineCode;
53 std::vector<std::std::unique_ptr<LocalVariableSymbol>>temporaries;
54 };
55
56 } }
57
58 #endif // CMAJOR_BINDER_BOUND_FUNCTION_INCLUDED