The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
IfElseStatement.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: IfElseStatement.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Encapsulates a If-Else statement of our programming language. //
10 // Inheritance: Statement. //
11 // Implements Composite pattern [Composite]. //
12 // Implements Visitor pattern [Concrete Element]. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 04-12-2006 //
15 // Modification date: 07-06-2007 //
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 
22 using Tools;
23 using TypeSystem;
24 using ErrorManagement;
25 
26 namespace AST {
35  public class IfElseStatement : Statement {
36  #region Fields
37 
41  private Expression condition;
42 
46  private List<MoveStatement> afterCondition;
47 
51  private Statement trueBranch;
52 
56  private Statement falseBranch;
57 
61  private List<ThetaStatement> thetaStats;
62 
67  private IList<SingleIdentifierExpression> referencesUsedInTrueBranch = new List<SingleIdentifierExpression>();
68 
73  private IList<SingleIdentifierExpression> referencesUsedInFalseBranch = new List<SingleIdentifierExpression>();
74 
75  #endregion
76 
77  #region Properties
78 
83  get { return condition; }
84  set { this.condition = value; }
85  }
86 
90  public List<MoveStatement> AfterCondition {
91  get { return this.afterCondition; }
92  set { this.afterCondition = value; }
93  }
94 
99  get { return trueBranch; }
100  }
101 
106  get { return falseBranch; }
107  }
108 
112  public List<ThetaStatement> ThetaStatements {
113  get { return this.thetaStats; }
114  set { this.thetaStats = value; }
115  }
116 
121  public IList<SingleIdentifierExpression> ReferencesUsedInTrueBranch {
122  get { return this.referencesUsedInTrueBranch; }
123  }
124 
129  public IList<SingleIdentifierExpression> ReferencesUsedInFalseBranch {
130  get { return this.referencesUsedInFalseBranch; }
131  }
132  #endregion
133 
134  #region Constructors
135 
144  public IfElseStatement(Expression exp, Statement trueBranch, Location location): base(location) {
145  this.condition = exp;
146  this.afterCondition = new List<MoveStatement>();
147  this.trueBranch = trueBranch;
148  this.falseBranch = new Block(location); //null?
149  this.thetaStats = new List<ThetaStatement>();
150  }
151 
161  public IfElseStatement(Expression exp, Statement trueBranch, Statement falseBranch, Location location)
162  : base(location) {
163  this.condition = exp;
164  this.afterCondition = new List<MoveStatement>();
165  this.trueBranch = trueBranch;
166  this.falseBranch = falseBranch;
167  this.thetaStats = new List<ThetaStatement>();
168  }
169 
170  #endregion
171 
172  #region HaveElseBlock
173 
178  public bool HaveElseBlock() {
179  if ((this.falseBranch is Block) && (((Block)this.falseBranch).StatementCount == 0))
180  return false;
181  return true;
182  }
183 
184  #endregion
185 
186  #region Accept()
187 
194  public override Object Accept(Visitor v, Object o) {
195  return v.Visit(this, o);
196  }
197  #endregion
198 
199  }
200 }
Abstract class encapsulate a programming language expression.
Definition: Expression.cs:37
Encapsulates a block of statements.
Definition: Block.cs:34
bool HaveElseBlock()
Returns true if the statement has a else block. Otherwise, false.
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
Abstract class to define different visits over the abstract syntax tree.
Definition: Visitor.cs:29
This class encapsulates a location in a specific file. Implements an Inmutable pattern. So it can be used in any context, that is his internal fields never change.
Definition: Location.cs:24
Abstract class represents a programming language statement.
Definition: Statement.cs:30
IList< SingleIdentifierExpression > ReferencesUsedInFalseBranch
The set of references that are used in the else body. Used for SSA purposes.
Expression Condition
Gets the condition expression of If-Else statement.
Statement FalseBranch
Gets the block executed when the condition is false.
Statement TrueBranch
Gets the block executed when the condition is true.
IfElseStatement(Expression exp, Statement trueBranch, Location location)
Constructor of IfElseStatement
Encapsulates a If-Else statement of our programming language.
IfElseStatement(Expression exp, Statement trueBranch, Statement falseBranch, Location location)
Constructor of IfElseStatement
List< ThetaStatement > ThetaStatements
Gets or sets the theta funcion statements
List< MoveStatement > AfterCondition
Gets or sets the statements after condition.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
IList< SingleIdentifierExpression > ReferencesUsedInTrueBranch
The set of references that are used in the if body. Used for SSA purposes.