-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFuncDef.h
More file actions
52 lines (41 loc) · 1.43 KB
/
FuncDef.h
File metadata and controls
52 lines (41 loc) · 1.43 KB
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
#pragma once
#include "Stmt.h"
#include "Syntax.h"
#include "Type.h"
#include <memory>
#include <string>
#include <vector>
/// Syntax for function definition.
class FuncDef
{
public:
/// Construct function definition syntax.
FuncDef( const Type& returnType, const std::string& name, std::vector<VarDeclPtr>&& params, SeqStmtPtr body )
: m_returnType( returnType )
, m_name( name )
, m_params( std::move( params ) )
, m_body( std::move( body ) )
{
}
/// Get the function return type.
const Type& GetReturnType() const { return m_returnType; }
/// Get the function name.
const std::string& GetName() const { return m_name; }
/// Get the parameter declarations.
const std::vector<VarDeclPtr>& GetParams() const { return m_params; }
/// Check whether the function definition has a body. (Builtin function declarations do not.)
bool HasBody() const { return bool( m_body ); }
/// Get the function body, which is a sequence of statements.
const SeqStmt& GetBody() const
{
assert( HasBody() && "Expected function body" );
return *m_body;
}
private:
Type m_returnType;
std::string m_name;
std::vector<VarDeclPtr> m_params;
SeqStmtPtr m_body;
};
/// Unique pointer to a function definition.
using FuncDefPtr = std::unique_ptr<FuncDef>;