File: ILToken.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (241 lines) | stat: -rw-r--r-- 8,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// ILToken.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)


using System;

namespace Mono.ILASM {

        public class ILToken : ICloneable {
                internal int token;
                internal object val;

                public static readonly ILToken Invalid;
                public static readonly ILToken EOF;

                public static readonly ILToken Dot;

                public static readonly ILToken OpenBrace;
                public static readonly ILToken CloseBrace;
                public static readonly ILToken OpenBracket;
                public static readonly ILToken CloseBracket;
                public static readonly ILToken OpenParens;
                public static readonly ILToken CloseParens;
                public static readonly ILToken Comma;
                public static readonly ILToken Colon;
                public static readonly ILToken DoubleColon;
                public static readonly ILToken Semicolon;
                public static readonly ILToken Assign;
                public static readonly ILToken Star;
                public static readonly ILToken Ampersand;
                public static readonly ILToken Plus;
                public static readonly ILToken Slash;
                public static readonly ILToken Bang;
                public static readonly ILToken Ellipsis;
                public static readonly ILToken Dash;
                public static readonly ILToken OpenAngleBracket;
                public static readonly ILToken CloseAngleBracket;

                private static readonly ILToken [] punctuations;

                /// <summary>
                /// </summary>
                static ILToken ()
                {
                        Invalid = new ILToken (-1, "invalid");
                        EOF = new ILToken (Token.EOF, "eof");

                        Dot = new ILToken (Token.DOT, ".");
                        OpenBrace = new ILToken (Token.OPEN_BRACE, "{");
                        CloseBrace = new ILToken (Token.CLOSE_BRACE, "}");
                        OpenBracket = new ILToken (Token.OPEN_BRACKET, "[");
                        CloseBracket = new ILToken (Token.CLOSE_BRACKET, "]");
                        OpenParens = new ILToken (Token.OPEN_PARENS, "(");
                        CloseParens = new ILToken (Token.CLOSE_PARENS, ")");
                        Comma = new ILToken (Token.COMMA, ",");
                        Colon = new ILToken (Token.COLON, ":");
                        DoubleColon = new ILToken (Token.DOUBLE_COLON, "::");
                        Semicolon = new ILToken (Token.SEMICOLON, ";");
                        Assign = new ILToken (Token.ASSIGN, "=");
                        Star = new ILToken (Token.STAR, "*");
                        Ampersand = new ILToken (Token.AMPERSAND, "&");
                        Plus = new ILToken (Token.PLUS, "+");
                        Slash = new ILToken (Token.SLASH, "/");
                        Bang = new ILToken (Token.BANG, "!");
                        Ellipsis = new ILToken (Token.ELLIPSIS, "...");
                        Dash = new ILToken (Token.DASH, "-");
                        OpenAngleBracket = new ILToken (Token.OPEN_ANGLE_BRACKET, "<");
                        CloseAngleBracket = new ILToken (Token.CLOSE_ANGLE_BRACKET, ">");

                        punctuations = new ILToken [] {
                                OpenBrace, CloseBrace,
                                OpenBracket, CloseBracket,
                                OpenParens, CloseParens,
                                Comma, Colon, Semicolon,
                                Assign, Star, Ampersand,
                                Plus, Slash, Bang,
                                OpenAngleBracket, CloseAngleBracket
                        };
                }

                /// <summary>
                /// </summary>
                public ILToken ()
                {
                }

                /// <summary>
                /// </summary>
                /// <param name="token"></param>
                /// <param name="val"></param>
                public ILToken (int token, object val)
                {
                        this.token = token;
                        this.val = val;
                }


                /// <summary>
                /// </summary>
                /// <param name="that"></param>
                public ILToken (ILToken that)
                {
                        this.token = that.token;
                        this.val = that.val;
                }



                /// <summary>
                /// </summary>
                public int TokenId {
                        get {
                                return token;
                        }
                }

                /// <summary>
                /// </summary>
                public object Value {
                        get {
                                return val;
                        }
                }


                /// <summary>
                /// </summary>
                /// <param name="that"></param>
                public virtual void CopyFrom (ILToken that)
                {
                        this.token = that.token;
                        this.val = that.val;
                }


                /// <summary>
                /// </summary>
                /// <returns></returns>
                public virtual object Clone ()
                {
                        return new ILToken (this);
                }


                /// <summary>
                /// </summary>
                /// <returns></returns>
                public override int GetHashCode ()
                {
                        int h = token;
                        if (val != null) h ^= val.GetHashCode ();
                        return h;
                }


                /// <summary>
                /// </summary>
                /// <returns></returns>
                public override string ToString ()
                {
                        return (token.ToString() + " : " + (val != null ? val.ToString () : "<null>"));
                }


                /// <summary>
                /// </summary>
                /// <param name="o"></param>
                /// <returns></returns>
                public override bool Equals (object o)
                {
                        bool res = (o != null);

                        if (res) {
                                res = Object.ReferenceEquals (this, o);
                                if (!res) {
                                        res = o is ILToken;
                                        if (res) {
                                                ILToken that = o as ILToken;
                                                res = (this.token == that.token) && (this.val.Equals (that.val));
                                        }
                                }
                        }

                        return res;
                }


                private static bool EqImpl (ILToken t1, ILToken t2)
                {
                        bool res = false;
                        if ((t1 as object) != null) {
                                res = t1.Equals (t2);
                        } else {
                                res = ((t2 as object) == null);
                        }

                        return res;
                }


                /// <summary>
                /// </summary>
                /// <param name="t1"></param>
                /// <param name="t2"></param>
                /// <returns></returns>
                public static bool operator == (ILToken t1, ILToken t2)
                {
                        return EqImpl (t1, t2);
                }

                /// <summary>
                /// </summary>
                /// <param name="t1"></param>
                /// <param name="t2"></param>
                /// <returns></returns>
                public static bool operator != (ILToken t1, ILToken t2)
                {
                        return !EqImpl (t1, t2);
                }



                /// <summary>
                /// </summary>
                /// <param name="ch"></param>
                /// <returns></returns>
                public static ILToken GetPunctuation (int ch)
                {
                        int id = "{}[](),:;=*&+/!<>".IndexOf ((char) ch);
                        ILToken res = null;

                        if (id != -1) {
                                res = punctuations [id];
                        }

                        return res;
                }


        }
}