The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
DeclarationSet.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: DeclarationSet.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Encapsulates a statement with several declarations. //
9 // Inheritance: Declaration. //
10 // Implements Composite pattern [Composite]. //
11 // Implements Visitor pattern [Concrete Element]. //
12 // -------------------------------------------------------------------------- //
13 // Create date: 03-01-2007 //
14 // Modification date: 04-01-2007 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Text;
20 
21 using Tools;
22 using TypeSystem;
23 using ErrorManagement;
24 
25 namespace AST
26 {
35  public class DeclarationSet : Declaration
36  {
37  #region Fields
38 
42  private List<Statement> declarations;
43 
44  #endregion
45 
46  #region Properties
47 
51  public int Count
52  {
53  get { return this.declarations.Count; }
54  }
55 
56  #endregion
57 
58  #region Constructor
59 
68  public DeclarationSet(string type, List<Statement> decls, Location location)
69  : base(type,location)
70  {
71  this.declarations = decls;
72  }
73 
74  #endregion
75 
76  #region GetDeclarationElement()
77 
83  public Statement GetDeclarationElement(int index)
84  {
85  return this.declarations[index];
86  }
87 
88  #endregion
89 
90  #region ContainsId()
91 
97  public bool ContainsId(string id)
98  {
99  for (int i = 0; i < this.declarations.Count; i++)
100  {
101  if (this.declarations[i] is IdDeclaration)
102  if (((IdDeclaration)this.declarations[i]).Identifier.Equals(id))
103  return true;
104  }
105  return false;
106  }
107 
108  #endregion
109 
110  #region Accept()
111 
118  public override Object Accept(Visitor v, Object o)
119  {
120  return v.Visit(this, o);
121  }
122 
123  #endregion
124  }
125 }
bool ContainsId(string id)
Searches the identifier and returns true if it exists.
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
int Count
Gets the number of declarations
Encapsulates a statement with several declarations.
Encapsulates a declaration of a concrete type.
Definition: Declaration.cs:34
Encapsulates a declaration.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
DeclarationSet(string type, List< Statement > decls, Location location)
Constructor of DeclarationSet
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
Statement GetDeclarationElement(int index)
Gets the element stored in the specified index.