Revision 7
Added by Willibald K. over 8 years ago
FunctionType.java | ||
---|---|---|
1 |
/**
|
|
2 |
*
|
|
3 |
* OOAS Compiler
|
|
4 |
*
|
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology.
|
|
6 |
* This code is based on the C# Version of the OOAS Compiler, which is
|
|
7 |
* copyright 2015 by the Institute of Software Technology, Graz University
|
|
8 |
* of Technology with portions copyright by the AIT Austrian Institute of
|
|
9 |
* Technology. All rights reserved.
|
|
10 |
*
|
|
11 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
|
12 |
*
|
|
13 |
* If you modify the file please update the list of contributors below to in-
|
|
14 |
* clude your name. Please also stick to the coding convention of using TABs
|
|
15 |
* to do the basic (block-level) indentation and spaces for anything after
|
|
16 |
* that. (Enable the display of special chars and it should be pretty obvious
|
|
17 |
* what this means.) Also, remove all trailing whitespace.
|
|
18 |
*
|
|
19 |
* Contributors:
|
|
20 |
* Willibald Krenn (AIT)
|
|
21 |
* Stephan Zimmerer (AIT)
|
|
22 |
* Markus Demetz (AIT)
|
|
23 |
* Christoph Czurda (AIT)
|
|
24 |
*
|
|
25 |
*/
|
|
1 |
/** |
|
2 |
* |
|
3 |
* OOAS Compiler |
|
4 |
* |
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology. |
|
6 |
* This code is based on the C# Version of the OOAS Compiler, which is |
|
7 |
* copyright 2015 by the Institute of Software Technology, Graz University |
|
8 |
* of Technology with portions copyright by the AIT Austrian Institute of |
|
9 |
* Technology. All rights reserved. |
|
10 |
* |
|
11 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED. |
|
12 |
* |
|
13 |
* If you modify the file please update the list of contributors below to in- |
|
14 |
* clude your name. Please also stick to the coding convention of using TABs |
|
15 |
* to do the basic (block-level) indentation and spaces for anything after |
|
16 |
* that. (Enable the display of special chars and it should be pretty obvious |
|
17 |
* what this means.) Also, remove all trailing whitespace. |
|
18 |
* |
|
19 |
* Contributors: |
|
20 |
* Willibald Krenn (AIT) |
|
21 |
* Stephan Zimmerer (AIT) |
|
22 |
* Markus Demetz (AIT) |
|
23 |
* Christoph Czurda (AIT) |
|
24 |
* |
|
25 |
*/ |
|
26 | 26 |
|
27 | 27 |
|
28 |
package org.momut.ooas.ast.types; |
|
29 |
|
|
30 |
import java.util.LinkedList; |
|
28 |
package org.momut.ooas.ast.types; |
|
31 | 29 |
|
30 |
import java.util.LinkedList; |
|
31 |
|
|
32 | 32 |
import org.momut.ooas.ast.IAstVisitor; |
33 |
|
|
34 |
/////////////////////////////////////////////// |
|
35 |
/// Complex Type: Function |
|
36 |
/// |
|
37 |
public final class FunctionType extends UlyssesType |
|
38 |
{ |
|
39 |
public enum FunctionTypeEnum { |
|
40 |
Observable (0), |
|
41 |
Controllable (1), |
|
42 |
Continuous (2), |
|
43 |
Internal (3), |
|
44 |
Method (4); |
|
45 |
|
|
46 |
public final int integerValue; // do not change, this is needed by the backends! i.e. public API |
|
47 |
|
|
48 |
private FunctionTypeEnum(int val) { |
|
49 |
integerValue = val; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
private Boolean m_miracleSafe = null; |
|
54 |
private boolean m_pure; |
|
55 |
private LinkedList<UlyssesType> m_parameter; |
|
56 |
private UlyssesType m_returnType; |
|
57 |
private final FunctionTypeEnum m_functionType; |
|
58 |
|
|
59 |
public Boolean isMiracleSafe() { return m_miracleSafe; } |
|
60 |
public boolean isPureFunction() { return m_pure; } |
|
61 |
public LinkedList<UlyssesType> parameter() { return m_parameter; } |
|
62 |
public UlyssesType returnType() { return m_returnType; } |
|
63 |
public FunctionTypeEnum functionType() { return m_functionType; } |
|
64 |
|
|
65 |
public FunctionType(FunctionTypeEnum functionType, LinkedList<UlyssesType> parameter, UlyssesType returnType) |
|
66 |
{ |
|
67 |
super (TypeKind.FunctionType, null); |
|
68 |
if (parameter != null) |
|
69 |
m_parameter = parameter; |
|
70 |
else |
|
71 |
m_parameter = new LinkedList<UlyssesType>(); |
|
72 |
m_returnType = returnType; |
|
73 |
m_functionType = functionType; |
|
74 |
m_miracleSafe = null; |
|
75 |
m_pure = false; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
public void AddParameterType(UlyssesType aType) |
|
80 |
{ |
|
81 |
m_parameter.addLast(aType); |
|
82 |
} |
|
83 |
|
|
84 |
public void SetReturnType(UlyssesType aType) |
|
85 |
{ |
|
86 |
m_returnType = aType; |
|
87 |
} |
|
88 |
|
|
89 |
public void SetMiracleSafe(boolean newValue) |
|
90 |
{ |
|
91 |
m_miracleSafe = newValue; |
|
92 |
} |
|
93 |
|
|
94 |
public void SetIsPureFunction(boolean newValue) |
|
95 |
{ |
|
96 |
m_pure = newValue; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public void Accept(IAstVisitor visitor) |
|
101 |
{ |
|
102 |
visitor.visit(this); |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public /*override*/ String AnonymousName() |
|
107 |
{ |
|
108 |
final StringBuilder result = new StringBuilder(); |
|
109 |
result.append("fun_"); |
|
110 |
result.append(m_functionType.toString()); |
|
111 |
result.append("_"); |
|
112 |
for (final UlyssesType sym: m_parameter) |
|
113 |
{ |
|
114 |
result.append(sym.toString()); |
|
115 |
result.append("_"); |
|
116 |
} |
|
117 |
result.append("_"); |
|
118 |
if (m_returnType != null) |
|
119 |
result.append(m_returnType.toString()); |
|
120 |
else |
|
121 |
result.append("void"); |
|
122 |
// the anonymous name MUST stay the same! |
|
123 |
// result.append("_"); |
|
124 |
// result.append(m_pure); |
|
125 |
return result.toString(); |
|
126 |
} |
|
127 |
} |
|
33 |
|
|
34 |
/////////////////////////////////////////////// |
|
35 |
/// Complex Type: Function |
|
36 |
/// |
|
37 |
public final class FunctionType extends UlyssesType |
|
38 |
{ |
|
39 |
public enum FunctionTypeEnum { |
|
40 |
Observable (0), |
|
41 |
Controllable (1), |
|
42 |
Continuous (2), |
|
43 |
Internal (3), |
|
44 |
Method (4); |
|
45 |
|
|
46 |
public final int integerValue; // do not change, this is needed by the backends! i.e. public API |
|
47 |
|
|
48 |
private FunctionTypeEnum(int val) { |
|
49 |
integerValue = val; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
private Boolean m_miracleSafe = null; |
|
54 |
private boolean m_pure; |
|
55 |
private LinkedList<UlyssesType> m_parameter; |
|
56 |
private UlyssesType m_returnType; |
|
57 |
private final FunctionTypeEnum m_functionType; |
|
58 |
|
|
59 |
public Boolean isMiracleSafe() { return m_miracleSafe; } |
|
60 |
public boolean isPureFunction() { return m_pure; } |
|
61 |
public LinkedList<UlyssesType> parameter() { return m_parameter; } |
|
62 |
public UlyssesType returnType() { return m_returnType; } |
|
63 |
public FunctionTypeEnum functionType() { return m_functionType; } |
|
64 |
|
|
65 |
public FunctionType(FunctionTypeEnum functionType, LinkedList<UlyssesType> parameter, UlyssesType returnType) |
|
66 |
{ |
|
67 |
super (TypeKind.FunctionType, null); |
|
68 |
if (parameter != null) |
|
69 |
m_parameter = parameter; |
|
70 |
else |
|
71 |
m_parameter = new LinkedList<UlyssesType>(); |
|
72 |
m_returnType = returnType; |
|
73 |
m_functionType = functionType; |
|
74 |
m_miracleSafe = null; |
|
75 |
m_pure = false; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
public void AddParameterType(UlyssesType aType) |
|
80 |
{ |
|
81 |
m_parameter.addLast(aType); |
|
82 |
} |
|
83 |
|
|
84 |
public void SetReturnType(UlyssesType aType) |
|
85 |
{ |
|
86 |
m_returnType = aType; |
|
87 |
} |
|
88 |
|
|
89 |
public void SetMiracleSafe(boolean newValue) |
|
90 |
{ |
|
91 |
m_miracleSafe = newValue; |
|
92 |
} |
|
93 |
|
|
94 |
public void SetIsPureFunction(boolean newValue) |
|
95 |
{ |
|
96 |
m_pure = newValue; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public void Accept(IAstVisitor visitor) |
|
101 |
{ |
|
102 |
visitor.visit(this); |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public /*override*/ String AnonymousName() |
|
107 |
{ |
|
108 |
final StringBuilder result = new StringBuilder(); |
|
109 |
result.append("fun_"); |
|
110 |
result.append(m_functionType.toString()); |
|
111 |
result.append("_"); |
|
112 |
for (final UlyssesType sym: m_parameter) |
|
113 |
{ |
|
114 |
result.append(sym.toString()); |
|
115 |
result.append("_"); |
|
116 |
} |
|
117 |
result.append("_"); |
|
118 |
if (m_returnType != null) |
|
119 |
result.append(m_returnType.toString()); |
|
120 |
else |
|
121 |
result.append("void"); |
|
122 |
// the anonymous name MUST stay the same! |
|
123 |
// result.append("_"); |
|
124 |
// result.append(m_pure); |
|
125 |
return result.toString(); |
|
126 |
} |
|
127 |
} |
Also available in: Unified diff
changing java, cpp, hpp files to unix line endings