My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /bsn.GoldParser/Grammar/GrammarObject.cs
c1604cdbf6c7 vs. 0b9792aeb310 Compare: vs.  Format:
Revision 0b9792aeb310
Go to: 
Project members, sign in to write a code review
/bsn.GoldParser/Grammar/GrammarObject.cs   c1604cdbf6c7 /bsn.GoldParser/Grammar/GrammarObject.cs   0b9792aeb310
1 // (C) 2010 Arsène von Wyss / bsn 1 // (C) 2010 Arsène von Wyss / bsn
2 using System; 2 using System;
3 using System.Runtime.CompilerServices;
4 3
5 namespace bsn.GoldParser.Grammar { 4 namespace bsn.GoldParser.Grammar {
5 /// <summary>
6 /// The base class for the grammar objects <see cref="DfaState"/>, <see cref="LalrAction"/>, <see cref="LalrState"/>, <see cref="Rule"/> and <see cref="Symbol"/>.
7 /// </summary>
8 /// <typeparam name="TSelf">The type of the grammar object implemented (self).</typeparam>
6 public abstract class GrammarObject<TSelf>: IEquatable<TSelf> where TSelf: GrammarObject<TSelf> { 9 public abstract class GrammarObject<TSelf>: IEquatable<TSelf> where TSelf: GrammarObject<TSelf> {
7 private readonly int index; 10 private readonly int index;
8 private readonly CompiledGrammar owner; 11 private readonly CompiledGrammar owner;
9 12
13 /// <summary>
14 /// Initializes a new instance of the <see cref="GrammarObject&lt;TSelf&gt;"/> class.
15 /// </summary>
16 /// <param name="owner">The owner grammar.</param>
17 /// <param name="index">The index.</param>
10 protected GrammarObject(CompiledGrammar owner, int index) { 18 protected GrammarObject(CompiledGrammar owner, int index) {
11 if (owner == null) { 19 if (owner == null) {
12 throw new ArgumentNullException("owner"); 20 throw new ArgumentNullException("owner");
13 } 21 }
14 this.owner = owner; 22 this.owner = owner;
15 this.index = index; 23 this.index = index;
16 } 24 }
17 25
18 /// <summary> 26 /// <summary>
19 /// Gets index of the LR state action. 27 /// Gets index of grammar object in the <see cref="CompiledGrammar"/>.
20 /// </summary> 28 /// </summary>
21 public int Index { 29 public int Index {
22 get { 30 get {
23 return index; 31 return index;
24 } 32 }
25 } 33 }
26 34
35 /// <summary>
36 /// Gets the owner.
37 /// </summary>
38 /// <value>The owner.</value>
27 public CompiledGrammar Owner { 39 public CompiledGrammar Owner {
28 get { 40 get {
29 return owner; 41 return owner;
30 } 42 }
31 } 43 }
32 44
33 public bool Equals(TSelf other) { 45 public override sealed bool Equals(object other) {
34 return ReferenceEquals(this, other); 46 return ReferenceEquals(this, other);
35 } 47 }
36 48
37 public sealed override int GetHashCode() { 49 public override sealed int GetHashCode() {
38 return base.GetHashCode(); 50 return base.GetHashCode();
39 } 51 }
40 52
41 public sealed override bool Equals(object other) { 53 public bool Equals(TSelf other) {
42 return ReferenceEquals(this, other); 54 return ReferenceEquals(this, other);
43 } 55 }
44 } 56 }
45 } 57 }
Powered by Google Project Hosting