PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/CastExpression.cs

http://github.com/icsharpcode/ILSpy
C# | 95 lines | 64 code | 11 blank | 20 comment | 5 complexity | cb64d2b43d205411855c41217e001502 MD5 | raw file
 1// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20
21namespace ICSharpCode.NRefactory.VB.Ast
22{
23	/// <summary>
24	/// CastType(Expression, AstType)
25	/// </summary>
26	public class CastExpression : Expression
27	{
28		public CastType CastType { get; set; }
29		
30		public VBTokenNode CastTypeToken {
31			get { return GetChildByRole (Roles.Keyword); }
32		}
33		
34		public AstType Type {
35			get { return GetChildByRole (Roles.Type); }
36			set { SetChildByRole (Roles.Type, value); }
37		}
38		
39		public Expression Expression {
40			get { return GetChildByRole (Roles.Expression); }
41			set { SetChildByRole (Roles.Expression, value); }
42		}
43		
44		public CastExpression ()
45		{
46		}
47		
48		public CastExpression (CastType castType, AstType castToType, Expression expression)
49		{
50			CastType = castType;
51			AddChild (castToType, Roles.Type);
52			AddChild (expression, Roles.Expression);
53		}
54		
55		public CastExpression (CastType castType, Expression expression)
56		{
57			CastType = castType;
58			AddChild (expression, Roles.Expression);
59		}
60		
61		public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
62		{
63			return visitor.VisitCastExpression (this, data);
64		}
65		
66		protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
67		{
68			CastExpression o = other as CastExpression;
69			return o != null && this.CastType == o.CastType && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match);
70		}
71	}
72	
73	public enum CastType
74	{
75		DirectCast,
76		TryCast,
77		CType,
78		CBool,
79		CByte,
80		CChar,
81		CDate,
82		CDec,
83		CDbl,
84		CInt,
85		CLng,
86		CObj,
87		CSByte,
88		CShort,
89		CSng,
90		CStr,
91		CUInt,
92		CULng,
93		CUShort
94	}
95}