Project

General

Profile

root / trunk / compiler / cppAst / ast / expressions / ValueExpression.hpp @ 4

1 2 krennw
/**
2
  *
3
  *                  OOAS Compiler - C++ AST
4
  *
5
  * Copyright 2015, AIT Austrian Institute of Technology.
6
  * All rights reserved.
7
  *
8
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
9
  *
10
  * If you modify the file please update the list of contributors below to in-
11
  * clude your name. Please also stick to the coding convention of using TABs
12
  * to do the basic (block-level) indentation and spaces for anything after
13
  * that. (Enable the display of special chars and it should be pretty obvious
14
  * what this means.) Also, remove all trailing whitespace.
15
  *
16
  * Contributors:
17
  *               Willibald Krenn (AIT)
18
  *               Stephan Zimmerer (AIT)
19
  *               Christoph Czurda (AIT)
20
  *
21
  */
22
23
24
25
26
#pragma once
27
28
#include <ast/expressions/LeafExpression.hpp>
29
#include <cstdint>
30
#include <ast/IAstVisitor.hpp>
31
32
namespace Ast {
33
34
template <class T>
35
class ValueExpression
36
        : public LeafExpression
37
{
38
protected:
39
        T m_value;
40
41
        ValueExpression(LeafTypeEnum type, ExpressionKind k):
42
                LeafExpression(type, k),
43
                m_value ()
44
        {};
45
        ValueExpression(const ValueExpression &toCopy):
46
                LeafExpression(toCopy),
47
                m_value(toCopy.m_value)
48
        {};
49
public:
50
        T value() {return m_value;};
51
};
52
53
class BoolValueExpression final
54
        : public ValueExpression<bool>
55
{
56
protected:
57
        BoolValueExpression():
58
                ValueExpression(LeafTypeEnum::_bool, ExpressionKind::Value_Bool)
59
        {};
60
        BoolValueExpression(const BoolValueExpression& toCopy):
61
                ValueExpression(toCopy)
62
        {};
63
64
        static BoolValueExpression* create(ExpressionKind) {return new BoolValueExpression();}
65
        static BoolValueExpression* createCopy(const BoolValueExpression& toCopy) {return new BoolValueExpression(toCopy);}
66
public:
67
        friend class Ast;
68
        friend class Expression;
69
70
        void init(std::int32_t line, std::int32_t pos, Type* typeRef,
71
                        IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef, bool value)
72
        {
73
                Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
74
                m_value = value;
75
        }
76
77
        void accept(IAstVisitor& visitor) override {visitor.visit(this);};
78
};
79
80
class IntValueExpression final
81
        : public ValueExpression<std::int64_t>
82
{
83
protected:
84
        IntValueExpression():
85
                ValueExpression(LeafTypeEnum::integer, ExpressionKind::Value_Integer)
86
        {};
87
        IntValueExpression(const IntValueExpression& toCopy):
88
                ValueExpression(toCopy)
89
        {};
90
91
        static IntValueExpression* create(ExpressionKind) {return new IntValueExpression();}
92
        static IntValueExpression* createCopy(const IntValueExpression& toCopy) {return new IntValueExpression(toCopy);}
93
public:
94
        friend class Ast;
95
        friend class Expression;
96
97
        void init(std::int32_t line, std::int32_t pos,
98
                        Type* typeRef,IdentifierList* callTargetsIdentifierListRef,
99
                                SymbolTable* symbTabRef, std::int64_t value)
100
        {
101
                Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
102
                m_value = value;
103
        }
104
105
        void accept(IAstVisitor& visitor) override {visitor.visit(this);};
106
};
107
108
class RefValueExpression final
109
        : public ValueExpression<void*>
110
{
111
protected:
112
        RefValueExpression():
113
                ValueExpression(LeafTypeEnum::reference, ExpressionKind::Value_Reference)
114
        {};
115
        RefValueExpression(const RefValueExpression& toCopy):
116
                ValueExpression(toCopy)
117
        {};
118
119
        static RefValueExpression* create(ExpressionKind) {return new RefValueExpression();}
120
        static RefValueExpression* createCopy(const RefValueExpression& toCopy) {return new RefValueExpression(toCopy);}
121
public:
122
        friend class Ast;
123
        friend class Expression;
124
125
        void init(std::int32_t line, std::int32_t pos, Type* typeRef,
126
                        IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef, void* value)
127
        {
128
                Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
129
                m_value = value;
130
        }
131
        void accept(IAstVisitor& visitor) override {visitor.visit(this);};
132
};
133
134
// skip:
135
// LeafTypeEnum::real;
136
// LeafTypeEnum::chr;
137
}