blob: ca121314248696a7e468092eb4b47b3747a91a17 (
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
|
#ifndef PCC_LITERALNODE_H
#define PCC_LITERALNODE_H
#include <string>
#include "BaseNode.hh"
#include "ExprNode.hh"
namespace pcc {
template <typename T> class LiteralNode : public ExprNode {
public:
LiteralNode(Context* context, std::shared_ptr<Type> type, T value);
Value CodeGen() override;
private:
T value_;
};
// the implementation of member functions of template classes must be put in
// header, but we put type-specific CodeGen() in the .cc file.
template <typename T>
LiteralNode<T>::LiteralNode(Context* context, std::shared_ptr<Type> type,
T value)
: ExprNode(context)
, value_(value) {
type_ = type;
}
using BooleanLiteralNode = LiteralNode<bool>;
using CharLiteralNode = LiteralNode<char>;
using IntegerLiteralNode = LiteralNode<int>;
using RealLiteralNode = LiteralNode<float>;
class StringLiteralNode : public ExprNode {
public:
StringLiteralNode(Context* context, std::shared_ptr<Type> type,
std::vector<char> value);
Value CodeGen() override;
private:
std::vector<char> value_;
};
} // namespace pcc
#endif
|