root / trunk / compiler / cppAst / ast / types / FunctionType.hpp @ 7
1 |
/**
|
---|---|
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/types/Type.hpp> |
29 |
#include <ast/Containers.hpp> |
30 |
#include <deque> |
31 |
|
32 |
namespace Ast {
|
33 |
|
34 |
enum class FunctionKind : std::uint8_t { |
35 |
Observable = 0,
|
36 |
Controllable = 1,
|
37 |
Continuous = 2,
|
38 |
Internal = 3,
|
39 |
Method = 4
|
40 |
}; |
41 |
|
42 |
class FunctionType final |
43 |
: public Type
|
44 |
{ |
45 |
protected:
|
46 |
FunctionKind m_functionType; |
47 |
bool m_pure;
|
48 |
bool m_static;
|
49 |
bool* m_miracleSafe;
|
50 |
Type* m_returnType; |
51 |
TypeList m_parameter; |
52 |
|
53 |
FunctionType(): |
54 |
Type(TypeKind::FunctionType), |
55 |
m_functionType (FunctionKind::Internal), |
56 |
m_pure(false),
|
57 |
m_static(false),
|
58 |
m_miracleSafe (nullptr),
|
59 |
m_returnType (nullptr),
|
60 |
m_parameter () |
61 |
{} |
62 |
|
63 |
FunctionType(const FunctionType& toCopy):
|
64 |
Type(toCopy), |
65 |
m_functionType (toCopy.m_functionType), |
66 |
m_pure(toCopy.m_pure), |
67 |
m_static(toCopy.m_static), |
68 |
m_miracleSafe (toCopy.m_miracleSafe), |
69 |
m_returnType (toCopy.m_returnType), |
70 |
m_parameter (toCopy.m_parameter) |
71 |
{} |
72 |
|
73 |
static FunctionType* create() {return new FunctionType();} |
74 |
static FunctionType* createCopy(const FunctionType& toCopy) {return new FunctionType(toCopy);} |
75 |
public:
|
76 |
friend class Ast; |
77 |
friend class Type; |
78 |
|
79 |
~FunctionType() override {
|
80 |
if (m_miracleSafe != nullptr) |
81 |
delete m_miracleSafe;
|
82 |
} |
83 |
|
84 |
void init(TypeIdentifier* identifierRef, bool anonymousType, |
85 |
TypeList* paramTypeListRef, Type* returnTypeRef, FunctionKind functionKind, bool isPure)
|
86 |
{ |
87 |
Type::init(identifierRef,anonymousType); |
88 |
m_parameter = std::move(*paramTypeListRef); |
89 |
m_returnType = returnTypeRef; |
90 |
m_functionType = functionKind; |
91 |
m_pure = isPure; |
92 |
} |
93 |
|
94 |
bool* isMiracleSafe() const {return m_miracleSafe;}; |
95 |
bool isStatic() const {return m_static;} |
96 |
bool isPureFunction() const {return m_pure;}; |
97 |
TypeList& parameter() {return m_parameter;};
|
98 |
Type* returnType() const {return m_returnType;}; |
99 |
FunctionKind functionType() const {return m_functionType;}; |
100 |
|
101 |
void addParameterType(Type* aType) {m_parameter.push_back(aType);};
|
102 |
void setReturnType(Type* aType) {m_returnType = aType;};
|
103 |
void setMiracleSafe(bool newValue) { |
104 |
if (m_miracleSafe == nullptr) |
105 |
m_miracleSafe = new bool(); |
106 |
*m_miracleSafe = newValue; |
107 |
} |
108 |
void setIsStatic(bool isStatic) {m_static = isStatic;} |
109 |
void setIsPureFunction(bool newValue) {m_pure = newValue;} |
110 |
void accept(IAstVisitor& visitor) override {visitor.visit(this);}; |
111 |
}; |
112 |
} |