|
/**
|
|
*
|
|
* 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)
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <base/TiresiasObject.hpp>
|
|
#include <ast/AstElement.hpp>
|
|
#include <ast/types/Type.hpp>
|
|
#include <cstdint>
|
|
#include <ast/Containers.hpp>
|
|
#include <ast/IAstVisitor.hpp>
|
|
#include <base/Exceptions.hpp>
|
|
|
|
|
|
namespace Ast {
|
|
|
|
|
|
/**
|
|
* You must not change the assigned values as this
|
|
* needs to be kept in sync with the definitions in Argos!
|
|
*/
|
|
enum class ExpressionKind : std::uint8_t
|
|
{
|
|
/*tern.*/
|
|
conditional = 0,
|
|
/*map binary*/
|
|
domresby = 1, domresto = 2, rngresby = 3, rngresto = 4, munion = 5,
|
|
/*set/list binary*/
|
|
conc = 6, diff = 7, inter = 8, elemin = 9, notelemin = 10, subset = 11, _union = 12,
|
|
/*numeric binary*/
|
|
div = 13, greater = 14, greaterequal = 15, idiv = 16, less = 17, lessequal = 18,
|
|
minus = 19, mod = 20, pow = 21, prod = 22, sum = 23,
|
|
/*bool binary*/
|
|
_and = 24, biimplies = 25, implies = 26, _or = 27,
|
|
/*other binary*/
|
|
equal = 28, notequal = 29, seqmod_mapoverride = 30,
|
|
/*map unary*/
|
|
dom = 31, range = 32, merge = 33,
|
|
/*set/list unary*/
|
|
card = 34, dconc = 35, dinter = 36, dunion = 37, elems = 38, head = 39,
|
|
inds = 40, len = 41, tail = 42,
|
|
/*unary numberic*/
|
|
unminus = 43, unplus = 44, _not = 45, abs = 46,
|
|
/*unary quantors*/
|
|
forall = 47, exists = 48,
|
|
/*Constructors*/
|
|
ListConstr = 49, SetConstr = 50, MapConstr = 51, TupleConstr = 52, ObjectConstr = 53, QValConstr = 54,
|
|
/* identifier */
|
|
Identifier = 55,
|
|
UnresolvedIdentifier = 56,
|
|
Type = 57,
|
|
/* tuple access and method call */
|
|
TupleMapAccess = 58, Call = 59,
|
|
/* point operator */
|
|
Access = 60,
|
|
/* primed */
|
|
Primed = 61,
|
|
/* cast */
|
|
Cast = 62,
|
|
/* fold */
|
|
foldLR = 63,
|
|
foldRL = 64,
|
|
|
|
/* values */
|
|
Value_Integer = 65,
|
|
Value_Bool = 66,
|
|
Value_Reference = 67,
|
|
|
|
EXPRESSIONKIND_LAST_ITEM = Value_Reference
|
|
};
|
|
|
|
#define EXPRESSIONKIND_NR_ITEMS ((std::uint8_t)ExpressionKind::EXPRESSIONKIND_LAST_ITEM + 1)
|
|
|
|
|
|
class Expression:
|
|
public AstElement
|
|
{
|
|
protected:
|
|
typedef Expression* (*ConstrPtr)(ExpressionKind k);
|
|
typedef Expression* (*CopyConstrPtr) (const Expression& toCopy);
|
|
|
|
ExpressionKind m_kind;
|
|
Type* m_type;
|
|
std::int32_t m_line;
|
|
std::int32_t m_pos;
|
|
SymbolTable* m_freeVariables;
|
|
FunctionIdentifierList m_callTargets;
|
|
|
|
Expression(ExpressionKind kind):
|
|
AstElement(AstNodeTypeEnum::expression),
|
|
m_kind(kind),
|
|
m_type (nullptr),
|
|
m_line (-1),
|
|
m_pos (-1),
|
|
m_freeVariables (nullptr)
|
|
{}
|
|
Expression(const Expression& toCopy):
|
|
AstElement(AstNodeTypeEnum::expression),
|
|
m_kind (toCopy.m_kind),
|
|
m_type (toCopy.m_type),
|
|
m_line (toCopy.m_line),
|
|
m_pos (toCopy.m_pos),
|
|
m_freeVariables (toCopy.m_freeVariables)
|
|
{}
|
|
~Expression()
|
|
{}
|
|
|
|
static Base::FuncPtr s_exprVmt [2][EXPRESSIONKIND_NR_ITEMS];
|
|
static Expression* createVirtual(ExpressionKind k);
|
|
static Expression* createVirtual(const Expression& toCopy);
|
|
public:
|
|
friend class Ast;
|
|
|
|
void init(
|
|
std::int32_t line,
|
|
std::int32_t pos,
|
|
Type* typeRef,IdentifierList* callTargetsIdentifierListRef,
|
|
SymbolTable* symbTabRef)
|
|
{
|
|
m_line = line;
|
|
m_pos = pos;
|
|
m_type = typeRef;
|
|
m_callTargets.clear();
|
|
if (callTargetsIdentifierListRef != nullptr) {
|
|
for (auto& id: *callTargetsIdentifierListRef) {
|
|
IdentifierKind kind = id->kind();
|
|
if (kind != IdentifierKind::MethodIdentifier &&
|
|
kind != IdentifierKind::NamedActionIdentifier)
|
|
{
|
|
throw new Base::InvalidArgumentException("Calltargets must be methods or actions.");
|
|
}
|
|
m_callTargets.push_back((FunctionIdentifier*)id);
|
|
}
|
|
}
|
|
m_freeVariables = symbTabRef;
|
|
}
|
|
|
|
|
|
ExpressionKind kind() const { return m_kind; };
|
|
Type* type() const { return m_type; };
|
|
std::int32_t line() const { return m_line; };
|
|
std::int32_t pos() const { return m_pos; };
|
|
SymbolTable* freeVariables() { return m_freeVariables; };
|
|
FunctionIdentifierList& callTargets() { return m_callTargets; };
|
|
|
|
void accept(IAstVisitor& visitor) override;
|
|
};
|
|
|
|
}
|