Project

General

Profile

root / trunk / compiler / cppAst / ast / StatementVisitor.cpp @ 6

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
 * StatementVisitor.cpp
27
 *
28
 *  Created on: Feb 4, 2014
29
 *      Author: willibald
30
 */
31
32
#include "StatementVisitor.hpp"
33
#include <ast/statements/GuardedCommand.hpp>
34
#include <ast/statements/SeqBlock.hpp>
35
#include <ast/statements/NondetBlock.hpp>
36
#include <ast/statements/PrioBlock.hpp>
37
38
39
namespace Ast {
40
41
42
StatementVisitor::StatementVisitor(CallContext* context):
43
                m_context(context)
44
{}
45
46
StatementVisitor::~StatementVisitor()
47
{}
48
49
50
void StatementVisitor::visitSub(AstElement* subElement, AstElement* parent) {
51
        if (subElement == nullptr)
52
                return;
53
        visitAstElement(subElement, parent);
54
}
55
56
void StatementVisitor::visitAstElement(AstElement* element, AstElement* ){
57
        switch (element->nodeType()) {
58
        case AstNodeTypeEnum::expression:
59
        case AstNodeTypeEnum::identifier:
60
        case AstNodeTypeEnum::type:
61
                error();
62
                break;
63
        case AstNodeTypeEnum::statement:
64
                static_cast<Statement*>(element)->accept(*this);
65
                break;
66
        default:
67
                m_context->logError("Internal error. Unknown AST type.");
68
                abort();
69
        }
70
}
71
72
void StatementVisitor::error() {
73
        m_context -> logError("Internal error. This visitor only supports statements.");
74
        abort();
75
}
76
77
//Identifiers
78
void StatementVisitor::visit(TypeIdentifier* ) { error(); };
79
void StatementVisitor::visit(EnumIdentifier* ) { error(); };
80
//void StatementVisitor::visit(ValuedEnumIdentifier* enumIdentifier) { error(); };
81
void StatementVisitor::visit(AttributeIdentifier* ) { error(); };
82
void StatementVisitor::visit(LocalVariableIdentifier* ) { error(); };
83
void StatementVisitor::visit(ParameterIdentifier* ) { error(); };
84
void StatementVisitor::visit(ExpressionVariableIdentifier* ) { error(); };
85
void StatementVisitor::visit(MethodIdentifier* ) { error(); };
86
void StatementVisitor::visit(NamedActionIdentifier* ) { error(); };
87
void StatementVisitor::visit(Module* ) { error(); };
88
void StatementVisitor::visit(ConstantIdentifier* ) { error(); };
89
void StatementVisitor::visit(UnspecIdentifierBlock* ) { error(); };
90
void StatementVisitor::visit(SeqIdentifierBlock* ) { error(); };
91
void StatementVisitor::visit(NondetIdentifierBlock* ) { error(); };
92
void StatementVisitor::visit(PrioIdentifierBlock* ) { error(); };
93
void StatementVisitor::visit(MainModule* ) { error(); };
94
95
//Types
96
void StatementVisitor::visit(IntType* ) { error(); };
97
void StatementVisitor::visit(BoolType* ) { error(); };
98
void StatementVisitor::visit(EnumType* ) { error(); };
99
void StatementVisitor::visit(ListType* ) { error(); };
100
void StatementVisitor::visit(TupleType* ) { error(); };
101
void StatementVisitor::visit(NullType* ) { error(); };
102
void StatementVisitor::visit(PointerType* ) { error(); };
103
void StatementVisitor::visit(FunctionType* ) { error(); };
104
void StatementVisitor::visit(ActionSystemType* ) { error(); };
105
106
// Statements
107
void StatementVisitor::visit(GuardedCommand* guardedCommand) {
108
        visitSub(guardedCommand->body(), guardedCommand);
109
};
110
111
void StatementVisitor::visit(Call* ) { };
112
void StatementVisitor::visit(Assignment* ) { };
113
void StatementVisitor::visit(SeqBlock* seqBlock) {
114
        for (auto& s: seqBlock->statements())
115
                visitSub(s, seqBlock);
116
};
117
void StatementVisitor::visit(NondetBlock* nondetBlock) {
118
        for (auto& s: nondetBlock->statements())
119
                visitSub(s, nondetBlock);
120
};
121
void StatementVisitor::visit(PrioBlock* prioBlock) {
122
        for (auto& s: prioBlock->statements())
123
                visitSub(s, prioBlock);
124
};
125
void StatementVisitor::visit(Skip* ) { };
126
void StatementVisitor::visit(Break* ) { };
127
void StatementVisitor::visit(Abort* ) { };
128
129
// Expressions
130
void StatementVisitor::visit(TernaryOperator* ) { error(); };
131
void StatementVisitor::visit(BinaryOperator* ) { error(); };
132
void StatementVisitor::visit(UnaryOperator* ) { error(); };
133
void StatementVisitor::visit(ExistsQuantifier* ) { error(); };
134
void StatementVisitor::visit(ForallQuantifier* ) { error(); };
135
void StatementVisitor::visit(ListConstructor* ) { error(); };
136
void StatementVisitor::visit(SetConstructor* ) { error(); };
137
void StatementVisitor::visit(TupleConstructor* ) { error(); };
138
void StatementVisitor::visit(ObjectConstructor* ) { error(); };
139
void StatementVisitor::visit(BoolValueExpression* ) { error(); };
140
void StatementVisitor::visit(IntValueExpression* ) { error(); };
141
void StatementVisitor::visit(RefValueExpression* ) { error(); };
142
void StatementVisitor::visit(IdentifierExpression* ) { error(); };
143
void StatementVisitor::visit(TypeExpression* ) { error(); };
144
void StatementVisitor::visit(TupleMapAccessExpression* ) { error(); };
145
void StatementVisitor::visit(CallExpression* ) { error(); };
146
void StatementVisitor::visit(AccessExpression* ) { error(); };
147
148
} /* namespace Ast */