The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SwitchSection.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: SwitchSection.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Encapsulates a Case 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: 01-08-2007 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Text;
20 
21 using Tools;
22 using ErrorManagement;
23 namespace AST
24 {
33  public class SwitchSection : Statement
34  {
35  #region Fields
36 
40  private List<SwitchLabel> labelSection;
41 
45  private Block caseBlock;
46 
47  #endregion
48 
49  #region Properties
50 
54  public Block SwitchBlock
55  {
56  get { return this.caseBlock; }
57  }
58 
62  public List<SwitchLabel> LabelSection
63  {
64  get { return this.labelSection; }
65  }
66 
70  public int LabelCount
71  {
72  get { return this.labelSection.Count; }
73  }
74 
75  #endregion
76 
77  #region Constructor
78 
87  public SwitchSection(List<SwitchLabel> labels, List<Statement> stats, Location location): base(location)
88  {
89  this.labelSection = labels;
90  this.caseBlock = new Block(stats, location);
91  }
92 
93  #endregion
94 
95  #region IsDefaultCase()
96 
101  public bool IsDefaultCase()
102  {
103  for (int i = 0; i < this.labelSection.Count; i++)
104  {
105  if (this.labelSection[i].SwitchSectionType == SectionType.Default)
106  return true;
107  }
108  return false;
109  }
110 
111  #endregion
112 
113  #region Accept()
114 
121  public override Object Accept(Visitor v, Object o)
122  {
123  return v.Visit(this, o);
124  }
125 
126  #endregion
127  }
128 }
Encapsulates a Case statement of our programming languages.
Encapsulates a block of statements.
Definition: Block.cs:34
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
bool IsDefaultCase()
Checks if the switch section has a default case.
Block SwitchBlock
Gets the code block of Case statement.
List< SwitchLabel > LabelSection
Gets the type of the Case statement (case or default)
int LabelCount
Gets the number of labels associated to the switch section.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
SectionType
Indicates if it is a case statement or a default case.
Definition: SwitchLabel.cs:31
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
SwitchSection(List< SwitchLabel > labels, List< Statement > stats, Location location)
Constructor of SwitchSection