Project

General

Profile

root / trunk / compiler / cppAst / ast / statements / Statement.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 <base/TiresiasObject.hpp>
29
#include <ast/AstElement.hpp>
30
#include <cstdint>
31
#include <base/Exceptions.hpp>
32
33
namespace Ast {
34
35
/**
36
 * You must not change the assigned values as this
37
 * needs to be kept in sync with the definitions in Argos!
38
 */
39
enum class StatementKind : std::uint8_t {
40
        GuardedCommand = 0,
41
        Call = 1,
42
        Assignment = 2,
43
        SeqBlock = 3,
44
        NondetBlock = 4,
45
        PrioBlock = 5,
46
        Skip = 6,
47
        Abort = 7,
48
        Kill = 8,
49
        QualConstraint = 9,
50
        Break = 10,
51
        STATEMENTKIND_LAST_ITEM = Break
52
};
53
54
#define STATEMENTKIND_NR_ITEMS ((std::uint8_t)StatementKind::STATEMENTKIND_LAST_ITEM + 1)
55
56
57
class Statement:
58
        public AstElement
59
{
60
protected:
61
        typedef Statement* (*ConstrPtr)();
62
        typedef Statement* (*CopyConstrPtr)(const Statement& toCopy);
63
64
        StatementKind m_kind;
65
        std::int32_t m_line;
66
        std::int32_t m_pos;
67
68
        Statement(StatementKind kind):
69
                AstElement(AstNodeTypeEnum::statement),
70
                m_kind(kind),
71
                m_line(-1),
72
                m_pos(-1)
73
        {};
74
75
        Statement(const Statement& toCopy):
76
                AstElement(AstNodeTypeEnum::statement),
77
                m_kind(toCopy.m_kind),
78
                m_line(toCopy.m_line),
79
                m_pos(toCopy.m_pos)
80
        {}
81
82
        static Base::FuncPtr s_stmntVmt [2][STATEMENTKIND_NR_ITEMS];
83
        static Statement* createVirtual(StatementKind aType); // virtual constructor used by Ast
84
        static Statement* createVirtual(const Statement& toCopy); // virtual copy constructor used by Ast
85
public:
86
        friend class Ast;
87
88
        void init(std::int32_t line, std::int32_t col) {
89
                m_line = line;
90
                m_pos = col;
91
        }
92
93
        StatementKind kind() const {return m_kind;}
94
        std::int32_t line() const {return m_line;};
95
        std::int32_t pos() const {return m_pos;};
96
97
        void accept(IAstVisitor& visitor) override;
98
        std::string toString() const {
99
                std::string result = "Stmnt ";
100
                result += std::to_string((std::uint32_t) m_kind );
101
                result += " at ";
102
                result += std::to_string(m_line);
103
                result += ":";
104
                result += std::to_string(m_pos);
105
                return result;
106
        }
107
};
108
}