summaryrefslogtreecommitdiff
path: root/node/LiteralNode.hh
blob: 392333408f2eeb47c44130f74c4a1b7427ed7f4b (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
#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);
    virtual Value CodeGen() override;
    virtual int Travel(Traveler& traveler) 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<long long>;
using RealLiteralNode = LiteralNode<float>;

class StringLiteralNode : public ExprNode {
  public:
    StringLiteralNode(Context* context, std::shared_ptr<Type> type,
                      std::vector<char> value);
    virtual Value CodeGen() override;
    virtual int Travel(Traveler& traveler) override;

  private:
    std::vector<char> value_;
};
} // namespace pcc

#endif