The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
TypeDefinition.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: TypeDefinition.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Encapsulates a definition of a concrete class or interface. //
9 // Inheritance: IdDeclaration. //
10 // Implements Composite pattern [Composite]. //
11 // Implements Visitor pattern [Concrete Element]. //
12 // -------------------------------------------------------------------------- //
13 // Create date: 18-01-2007 //
14 // Modification date: 02-03-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 {
34  public class TypeDefinition : IdDeclaration {
35  #region Fields
36 
40  protected List<Declaration> members;
41 
45  private List<Modifier> modifiers;
46 
50  private List<string> baseClass;
51 
52  #endregion
53 
54  #region Properties
55 
59  public int MemberCount {
60  get { return this.members.Count; }
61  }
62 
66  public List<Modifier> Modifiers {
67  get { return this.modifiers; }
68  }
69 
73  public List<string> BaseClass {
74  get { return this.baseClass; }
75  }
76 
77  #endregion
78 
79  #region Constructor
80 
90  protected TypeDefinition(SingleIdentifierExpression id, List<Modifier> mods, List<string> bases, List<Declaration> decls, Location location)
91  : base(id, id.Identifier, location) {
92  this.modifiers = mods;
93  this.baseClass = bases;
94  this.members = decls;
95  }
96 
97  #endregion
98 
99  #region AddNewField()
100 
105  public void AddNewField(FieldDeclaration f) {
106  this.members.Insert(0, f);
107  }
108 
109  #endregion
110 
111  #region GetMemberElement()
112 
118  public Declaration GetMemberElement(int index) {
119  if (index >= 0 && index < this.members.Count)
120  return this.members[index];
121  else
122  ErrorManager.Instance.NotifyError(new ArgumentOutOfRangeError(index, "TypeDefinition.GetMemberElement"));
123 
124  return null;
125  }
126 
127  #endregion
128 
129  #region RemoveMemberElement()
130 
135  public void RemoveMemberElement(int index) {
136  if (index >= 0 && index < this.members.Count)
137  this.members.RemoveAt(index);
138  else
139  ErrorManager.Instance.NotifyError(new ArgumentOutOfRangeError(index, "TypeDefinition.RemoveMemberElement"));
140  }
141 
142  #endregion
143 
144  #region Accept()
145 
152  public override Object Accept(Visitor v, Object o) {
153 
154  return v.Visit(this, o);
155  }
156 
157  #endregion
158  }
159 }
int MemberCount
Gets the number of members
List< Modifier > Modifiers
Gets the list of modifiers
void AddNewField(FieldDeclaration f)
Adds a new field declaration.
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
TypeDefinition(SingleIdentifierExpression id, List< Modifier > mods, List< string > bases, List< Declaration > decls, Location location)
Constructor of TypeDefinition.
List< Declaration > members
Stores the members of the class.
List< string > BaseClass
Gets the list of base class
Encapsulates a identifier expression of our programming language.
Declaration GetMemberElement(int index)
Gets the element stored in the specified index.
Encapsulates a declaration of a concrete type.
Definition: Declaration.cs:34
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
Encapsulates a declaration.
Represents the error occurred when the argument value is out of range.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
Encapsulates a definition of a concrete class or interface.
Encapsulates a declaration of a concrete field.
string Identifier
Gets the name associated to the declaration
void RemoveMemberElement(int index)
Deletes the element stored in the specified index.