The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SwitchStatement.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: SwitchStatement.cs //
6 // Authors: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Francisco Ortin - francisco.ortin@gmail.com //
8 // Description: //
9 // Encapsulates a Switch statement of our programming languages. //
10 // Inheritance: Statement. //
11 // Implements Composite pattern [Composite]. //
12 // Implements Visitor pattern [Concrete Element]. //
13 // -------------------------------------------------------------------------- //
14 // Create date: 05-12-2006 //
15 // Modification date: 01-08-2007 //
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 
22 using Tools;
23 using ErrorManagement;
24 
25 namespace AST
26 {
35  public class SwitchStatement : Statement
36  {
37  #region Fields
38 
42  private Expression condition;
43 
47  private List<SwitchSection> switchBlock;
48 
52  private List<MoveStatement> afterCondition;
53 
57  private List<ThetaStatement> thetaStats;
58 
63  private IDictionary<Block, IList<SingleIdentifierExpression>> referencesUsedCases = new Dictionary<Block, IList<SingleIdentifierExpression>>();
64 
68  private int labels = -1;
69 
70  #endregion
71 
72  #region Properties
73 
77  public Expression Condition
78  {
79  get { return condition; }
80  set { condition = value; }
81  }
82 
86  public int SwitchBlockCount
87  {
88  get { return this.switchBlock.Count; }
89  }
90 
94  public List<MoveStatement> AfterCondition
95  {
96  get { return this.afterCondition; }
97  set { this.afterCondition = value; }
98  }
99 
103  public List<ThetaStatement> ThetaStatements
104  {
105  get { return this.thetaStats; }
106  set { this.thetaStats = value; }
107  }
108 
113  public IDictionary<Block, IList<SingleIdentifierExpression>> ReferencesUsedCases {
114  get { return this.referencesUsedCases; }
115  }
116 
117  #endregion
118 
119  #region Constructor
120 
128  public SwitchStatement(Expression cond, List<SwitchSection> sections, Location location)
129  : base(location)
130  {
131  this.condition = cond;
132  this.switchBlock = sections;
133  this.afterCondition = new List<MoveStatement>();
134  this.thetaStats = new List<ThetaStatement>();
135  }
136 
137  #endregion
138 
139  #region LabelCount
140 
145  public int LabelCount()
146  {
147  if (this.labels == -1)
148  {
149  this.labels = 0;
150  for (int i = 0; i < this.switchBlock.Count; i++)
151  this.labels += this.switchBlock[i].LabelCount;
152  }
153  return this.labels;
154  }
155 
156  #endregion
157 
158  #region GetSwitchSectionElement()
159 
166  {
167  return this.switchBlock[index];
168  }
169 
170  #endregion
171 
172  #region Accept()
173 
180  public override Object Accept(Visitor v, Object o)
181  {
182  return v.Visit(this, o);
183  }
184 
185  #endregion
186  }
187 }
int SwitchBlockCount
Gets the number of cases used in Switch statement.
IDictionary< Block, IList< SingleIdentifierExpression > > ReferencesUsedCases
The set of references used in each case body, including the default section. Used for SSA purposes...
Abstract class encapsulate a programming language expression.
Definition: Expression.cs:37
Encapsulates a Case statement of our programming languages.
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
SwitchSection GetSwitchSectionElement(int index)
Gets the element stored in the specified index.
List< ThetaStatement > ThetaStatements
Gets or sets the theta funcion statements
SwitchStatement(Expression cond, List< SwitchSection > sections, Location location)
Constructor of SwitchStatement
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
int LabelCount()
Gets the number of labels the switch statement has.
Expression Condition
Gets the condition expression of Switch Statement.
List< MoveStatement > AfterCondition
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
Encapsulates a Switch statement of our programming languages.