The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ClassDefinition.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: ClassDefinition.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Encapsulates a definition of a concrete class. //
9 // Inheritance: IdDeclaration. //
10 // Implements Composite pattern [Composite]. //
11 // Implements Visitor pattern [Concrete Element]. //
12 // -------------------------------------------------------------------------- //
13 // Create date: 13-12-2006 //
14 // Modification date: 124-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 {
35  #region Constructor
36 
46  public ClassDefinition(SingleIdentifierExpression id, List<Modifier> mods, List<string> bases, List<Declaration> decls, Location location)
47  : base(id, mods, bases, decls, location) {
48  bool constructorFound = false;
49 
50  if (mods.Contains(Modifier.Static)) // Static class needs static constructor
51  {
52  // Check default constructor.
53  for (int i = 0; i < decls.Count; i++) {
54  if (decls[i] is MethodDeclaration) {
55  if ((((MethodDeclaration)decls[i]).Identifier.Equals(id.Identifier)) && (((MethodDeclaration)decls[i]).ModifiersInfo.Contains(Modifier.Static))) {
56  constructorFound = true;
57  break;
58  }
59  }
60  }
61  } else // Non static class needs non static constructor
62  {
63  // Check default constructor.
64  for (int i = 0; i < decls.Count; i++) {
65  if (decls[i] is MethodDeclaration) {
66  if (((MethodDeclaration)decls[i]).Identifier.Equals(id.Identifier)) // && (!(((MethodDeclaration)decls[i]).ModifiersInfo.Contains(Modifier.Static))))
67  {
68  constructorFound = true;
69  break;
70  }
71  }
72  }
73  }
74 
75  if (!constructorFound) {
76  List<Modifier> m = new List<Modifier>();
77  if (mods.Contains(Modifier.Static))
78  m.Add(Modifier.Static);
79  else
80  m.Add(Modifier.Public);
81  this.members.Add(new ConstructorDefinition(id, m, new List<Parameter>(), null, new Block(location), location));
82  }
83  }
84 
85  #endregion
86 
87  #region Accept()
88 
95  public override Object Accept(Visitor v, Object o) {
96  return v.Visit(this, o);
97  }
98 
99  #endregion
100  }
101 }
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
Encapsulates a identifier expression of our programming language.
Encapsulates a declaration of a concrete method.
ClassDefinition(SingleIdentifierExpression id, List< Modifier > mods, List< string > bases, List< Declaration > decls, Location location)
Constructor of ClassDefinition.
Encapsulates a definition of a concrete constructor.
Location location
Location: Encapsulates in one object the line, column and filename
Definition: AstNode.cs:39
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
Encapsulates a definition of a concrete class or interface.
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
string Identifier
Gets the name associated to the declaration
Encapsulates a definition of a concrete class.