The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
Location.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project StaDyn //
4 // -------------------------------------------------------------------------- //
5 // File: Location.cs //
6 // Author: Daniel Zapico Rodríguez - danzapico@gmail.com //
7 // Francisco Ortín Soler - ortin@uniovi.es //
8 // Description: //
9 // It Stores de location of a text element. I.e.class definition, an arith-//
10 // metical operation,etc. //
11 // Specificly, it is used for locating anspecific token of source code. //
12 // An inmutable pattern is used because the instances of this class are //
13 // passive in nature. The instance don not ever need to change its state. //
14 // -------------------------------------------------------------------------- //
15 // Create date: 05-03-2009 //
16 // Modification date: 05-03-2009 //
18 namespace ErrorManagement {
24  public class Location {
25 
26  #region Fields
27  private string fileName;
34  private int line;
38  private int column;
39 
44  bool valid = false;
45  #endregion
46 
47  #region Properties
48 
52  public string FileName {
53  get { return fileName; }
54  }
58  public int Line {
59  get { return line; }
60  }
64  public int Column {
65  get { return column; }
66  }
67 
72  public bool Valid {
73  get { return this.valid; }
74  }
75 
76  #endregion
77 
78  #region Constructor
79 
86  public Location(string fileName, int lineNumber, int columnNumber) {
87  this.line = lineNumber;
88  this.column = columnNumber;
89  this.fileName = fileName;
90  this.valid = true;
91  }
92 
93  public Location() {
94  this.valid = false;
95  }
96  #endregion
97 
98  #region ToString
99 
102 
103  public override string ToString() {
104  if (valid)
105  return FileName + "[" + Line + ", " + Column + "]";
106  return "[Cannot stablish location of the element]";
107  }
108  #endregion
109 
110  #region Equals & HasCode
111  public override int GetHashCode() {
112  return this.line.GetHashCode() * this.column.GetHashCode() * this.fileName.GetHashCode();
113  }
114 
115 
116  public override bool Equals(object obj) {
117  if (obj == this) return true;
118 
119  Location node = obj as Location;
120 
121  if (obj == null) return false;
122 
123  return this.line == node.line && this.column == node.column && this.fileName.Equals(node.fileName);
124  }
125  public Location Clone() {
126  return new Location(this.fileName, this.line, this.column);
127  }
128  #endregion
129  }
130 }
override bool Equals(object obj)
Definition: Location.cs:116
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
int Column
Gets column where the item is located
Definition: Location.cs:64
int Line
Gets line where the item is located
Definition: Location.cs:58
Location(string fileName, int lineNumber, int columnNumber)
Constructor of Location.
Definition: Location.cs:86
bool Valid
Indicates whether the object state has been created with a coherent state. In case it is false...
Definition: Location.cs:72
override int GetHashCode()
Definition: Location.cs:111
override string ToString()
Definition: Location.cs:103
string FileName
Gets de name of the file
Definition: Location.cs:52