root/trunk/compiler/cppAst/ast/expressions/ValueExpression.hpp
7 | krennw | /**
|
|
*
|
|||
* OOAS Compiler - C++ AST
|
|||
*
|
|||
* Copyright 2015, AIT Austrian Institute of Technology.
|
|||
* All rights reserved.
|
|||
*
|
|||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
|||
*
|
|||
* If you modify the file please update the list of contributors below to in-
|
|||
* clude your name. Please also stick to the coding convention of using TABs
|
|||
* to do the basic (block-level) indentation and spaces for anything after
|
|||
* that. (Enable the display of special chars and it should be pretty obvious
|
|||
* what this means.) Also, remove all trailing whitespace.
|
|||
*
|
|||
* Contributors:
|
|||
* Willibald Krenn (AIT)
|
|||
* Stephan Zimmerer (AIT)
|
|||
* Christoph Czurda (AIT)
|
|||
*
|
|||
*/
|
|||
2 | krennw | ||
#pragma once
|
|||
#include <ast/expressions/LeafExpression.hpp>
|
|||
#include <cstdint>
|
|||
#include <ast/IAstVisitor.hpp>
|
|||
namespace Ast {
|
|||
template <class T>
|
|||
class ValueExpression
|
|||
: public LeafExpression
|
|||
{
|
|||
protected:
|
|||
T m_value;
|
|||
ValueExpression(LeafTypeEnum type, ExpressionKind k):
|
|||
LeafExpression(type, k),
|
|||
m_value ()
|
|||
{};
|
|||
ValueExpression(const ValueExpression &toCopy):
|
|||
LeafExpression(toCopy),
|
|||
m_value(toCopy.m_value)
|
|||
{};
|
|||
public:
|
|||
T value() {return m_value;};
|
|||
};
|
|||
class BoolValueExpression final
|
|||
: public ValueExpression<bool>
|
|||
{
|
|||
protected:
|
|||
BoolValueExpression():
|
|||
ValueExpression(LeafTypeEnum::_bool, ExpressionKind::Value_Bool)
|
|||
{};
|
|||
BoolValueExpression(const BoolValueExpression& toCopy):
|
|||
ValueExpression(toCopy)
|
|||
{};
|
|||
static BoolValueExpression* create(ExpressionKind) {return new BoolValueExpression();}
|
|||
static BoolValueExpression* createCopy(const BoolValueExpression& toCopy) {return new BoolValueExpression(toCopy);}
|
|||
public:
|
|||
friend class Ast;
|
|||
friend class Expression;
|
|||
void init(std::int32_t line, std::int32_t pos, Type* typeRef,
|
|||
IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef, bool value)
|
|||
{
|
|||
Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
|
|||
m_value = value;
|
|||
}
|
|||
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
|||
};
|
|||
class IntValueExpression final
|
|||
: public ValueExpression<std::int64_t>
|
|||
{
|
|||
protected:
|
|||
IntValueExpression():
|
|||
ValueExpression(LeafTypeEnum::integer, ExpressionKind::Value_Integer)
|
|||
{};
|
|||
IntValueExpression(const IntValueExpression& toCopy):
|
|||
ValueExpression(toCopy)
|
|||
{};
|
|||
static IntValueExpression* create(ExpressionKind) {return new IntValueExpression();}
|
|||
static IntValueExpression* createCopy(const IntValueExpression& toCopy) {return new IntValueExpression(toCopy);}
|
|||
public:
|
|||
friend class Ast;
|
|||
friend class Expression;
|
|||
void init(std::int32_t line, std::int32_t pos,
|
|||
Type* typeRef,IdentifierList* callTargetsIdentifierListRef,
|
|||
SymbolTable* symbTabRef, std::int64_t value)
|
|||
{
|
|||
Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
|
|||
m_value = value;
|
|||
}
|
|||
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
|||
};
|
|||
class RefValueExpression final
|
|||
: public ValueExpression<void*>
|
|||
{
|
|||
protected:
|
|||
RefValueExpression():
|
|||
ValueExpression(LeafTypeEnum::reference, ExpressionKind::Value_Reference)
|
|||
{};
|
|||
RefValueExpression(const RefValueExpression& toCopy):
|
|||
ValueExpression(toCopy)
|
|||
{};
|
|||
static RefValueExpression* create(ExpressionKind) {return new RefValueExpression();}
|
|||
static RefValueExpression* createCopy(const RefValueExpression& toCopy) {return new RefValueExpression(toCopy);}
|
|||
public:
|
|||
friend class Ast;
|
|||
friend class Expression;
|
|||
void init(std::int32_t line, std::int32_t pos, Type* typeRef,
|
|||
IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef, void* value)
|
|||
{
|
|||
Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
|
|||
m_value = value;
|
|||
}
|
|||
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
|||
};
|
|||
// skip:
|
|||
// LeafTypeEnum::real;
|
|||
// LeafTypeEnum::chr;
|
|||
}
|