The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ForStatement.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: ForStatement.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Encapsulates a For statement of our programming languages. //
9 // Inheritance: Statement. //
10 // Implements Composite pattern [Composite]. //
11 // Implements Visitor pattern [Concrete Element]. //
12 // -------------------------------------------------------------------------- //
13 // Create date: 05-12-2006 //
14 // Modification date: 25-04-2007 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Text;
20 
21 using Tools;
22 using ErrorManagement;
23 
24 namespace AST
25 {
34  public class ForStatement : Statement
35  {
36  #region Fields
37 
41  private List<Statement> initializer;
42 
46  private Expression condition;
47 
51  private List<Statement> iterator;
52 
56  private Statement forStatement;
57 
61  private List<MoveStatement> afterInit;
62 
66  private List<ThetaStatement> beforeCondition;
67 
71  private List<MoveStatement> afterCondition;
72 
76  private Block auxiliarInit;
77 
78  #endregion
79 
80  #region Properties
81 
85  public int InitializerCount
86  {
87  get { return this.initializer.Count; }
88  }
89 
93  public Expression Condition
94  {
95  get { return condition; }
96  set { condition = value; }
97  }
98 
102  public int IteratorCount
103  {
104  get { return this.iterator.Count; }
105  }
106 
110  public Statement Statements
111  {
112  get { return forStatement; }
113  }
114 
118  public List<MoveStatement> AfterInit
119  {
120  get { return this.afterInit; }
121  set { this.afterInit = value; }
122  }
123 
127  public List<MoveStatement> AfterCondition
128  {
129  get { return this.afterCondition; }
130  set { this.afterCondition = value; }
131  }
132 
136  public List<ThetaStatement> BeforeCondition
137  {
138  get { return this.beforeCondition; }
139  set { this.beforeCondition = value; }
140  }
141 
145  public Block AuxInitializer
146  {
147  get { return this.auxiliarInit = new Block(location); }
148  }
149 
150  #endregion
151 
152  #region Constructor
153 
164  public ForStatement(List<Statement> init, Expression cond, List<Statement> iter, Statement statements, Location location)
165  : base(location)
166  {
167  if (init != null)
168  this.initializer = init;
169  else
170  this.initializer = new List<Statement>();
171 
172  this.condition = cond;
173 
174  if (iter != null)
175  this.iterator = iter;
176  else
177  this.iterator = new List<Statement>();
178 
179  this.forStatement = statements;
180 
181  this.afterInit = new List<MoveStatement>();
182  this.beforeCondition = new List<ThetaStatement>();
183  this.afterCondition = new List<MoveStatement>();
184  }
185 
186  #endregion
187 
188  #region GetInitializerElement()
189 
196  {
197  return getElement(this.initializer, index);
198  }
199 
200  #endregion
201 
202  #region GetIteratorElement()
203 
209  public Statement GetIteratorElement(int index)
210  {
211  return getElement(this.iterator, index);
212  }
213 
214  #endregion
215 
216  #region getElement()
217 
223  private Statement getElement(List<Statement> list, int index)
224  {
225  return list[index];
226  }
227 
228  #endregion
229 
230  #region Accept()
231 
238  public override Object Accept(Visitor v, Object o)
239  {
240  return v.Visit(this, o);
241  }
242 
243  #endregion
244 
245  #region UpdateInitializer()
246 
250  internal void UpdateInitializer()
251  {
252  for (int i = 0; i < this.auxiliarInit.StatementCount; i++)
253  {
254  this.initializer.Insert(0, this.auxiliarInit.GetStatementElement(i));
255  }
256  this.auxiliarInit = null;
257  }
258 
259  #endregion
260  }
261 }
Abstract class encapsulate a programming language expression.
Definition: Expression.cs:37
Encapsulates a block of statements.
Definition: Block.cs:34
Statement GetIteratorElement(int index)
Gets the element stored in the specified index.
Expression Condition
Gets the condition expression of For Statement.
Definition: ForStatement.cs:94
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
Block AuxInitializer
Gets the auxiliar block of variable declarations
Encapsulates a For statement of our programming languages.
Definition: ForStatement.cs:34
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
List< ThetaStatement > BeforeCondition
Gets or sets the statements before condition.
int InitializerCount
Gets the number of initializer expressions of For statement.
Definition: ForStatement.cs:86
int IteratorCount
Gets the number of iterator expression of For loop.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
Statement Statements
Gets the block executed while the condition is true.
ForStatement(List< Statement > init, Expression cond, List< Statement > iter, Statement statements, Location location)
Constructor of ForStatement
List< MoveStatement > AfterCondition
Gets or sets the statements after condition.
List< MoveStatement > AfterInit
Gets or sets the statements to use after initialization
Statement GetInitializerElement(int index)
Gets the element stored in the specified index.