root / trunk / compiler / ooasCompiler / src / org / momut / ooas / ast / statements / GuardedCommand.java @ 7
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 |
|
27 |
|
28 |
package org.momut.ooas.ast.statements; |
29 |
|
30 |
import org.momut.ooas.ast.IAstVisitor; |
31 |
import org.momut.ooas.ast.IScope; |
32 |
import org.momut.ooas.ast.expressions.Expression; |
33 |
import org.momut.ooas.ast.identifiers.Identifier; |
34 |
import org.momut.ooas.utils.exceptions.ArgumentException; |
35 |
import org.momut.ooas.utils.exceptions.InternalCompilerException; |
36 |
|
37 |
///////////////////////////////////////////////
|
38 |
/// Guarded Command
|
39 |
///
|
40 |
public final class GuardedCommand extends Statement implements IScope |
41 |
{ |
42 |
private Expression m_guard; |
43 |
private Statement m_body; |
44 |
private boolean m_isQualitative; |
45 |
private IScope m_parentScope;
|
46 |
|
47 |
public Expression guard() { return m_guard; } |
48 |
public Statement body() { return m_body; } |
49 |
public boolean isQualitative() { return m_isQualitative; } |
50 |
|
51 |
|
52 |
public GuardedCommand(Expression aGuard, Block aBlock, int aline, int apos) |
53 |
{ |
54 |
super (StatementKind.GuardedCommand, aline, apos);
|
55 |
m_guard = aGuard; |
56 |
m_isQualitative = false;
|
57 |
m_body = aBlock; |
58 |
checkBody(); |
59 |
} |
60 |
|
61 |
public GuardedCommand(GuardedCommand toCopy)
|
62 |
{ |
63 |
super (toCopy);
|
64 |
m_guard = toCopy.m_guard; |
65 |
m_body = toCopy.m_body; |
66 |
m_isQualitative = toCopy.m_isQualitative; |
67 |
m_parentScope = toCopy.m_parentScope; |
68 |
} |
69 |
|
70 |
@Override
|
71 |
public /*override*/ Statement Clone() |
72 |
{ |
73 |
return new GuardedCommand(this); |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public /*override*/ void Accept(IAstVisitor visitor) |
78 |
{ |
79 |
visitor.visit(this);
|
80 |
} |
81 |
|
82 |
public void SetGuard(Expression newGuard) |
83 |
{ |
84 |
if (newGuard == null) |
85 |
throw new ArgumentException(); |
86 |
m_guard = newGuard; |
87 |
} |
88 |
|
89 |
public void SetBody(Statement newBody) |
90 |
{ |
91 |
if (newBody == null) |
92 |
throw new ArgumentException(); |
93 |
m_body = newBody; |
94 |
checkBody(); |
95 |
} |
96 |
|
97 |
private void checkBody() { |
98 |
if (m_body instanceof IScope) { |
99 |
final IScope s = (IScope) m_body;
|
100 |
if (s.GetParentScope() == null) |
101 |
s.SetParentScope(this);
|
102 |
else if (s.GetParentScope() != this) |
103 |
throw new InternalCompilerException("Internal Error: GuardedCommandBody has parent set to different method than it was added to."); |
104 |
} |
105 |
} |
106 |
|
107 |
public void SetIsQualitative(boolean newVal) |
108 |
{ |
109 |
m_isQualitative = newVal; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public Identifier ResolveIdentifier(String aName) { |
114 |
return null; |
115 |
} |
116 |
@Override
|
117 |
public IScope GetParentScope() {
|
118 |
return m_parentScope;
|
119 |
} |
120 |
@Override
|
121 |
public void SetParentScope(IScope parentScope) { |
122 |
m_parentScope = parentScope; |
123 |
} |
124 |
@Override
|
125 |
public void AddIdentifier(Identifier anIdentifier, Object tag) { |
126 |
throw new InternalCompilerException("Cannot add identifier to guarded command."); |
127 |
} |
128 |
|
129 |
} |