Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/Expressions/CastExpression.cs

Last change on this file was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 4.7 KB
Line 
1//
2// CastExpression.cs
3// 
4// Author:
5//       Mike Krüger <mkrueger@novell.com>
6//
7// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
8//
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the Software is
14// furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included in
17// all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25// THE SOFTWARE.
26using System.Collections.Generic;
27using System;
28
29namespace ICSharpCode.NRefactory.CSharp
30{
31  /// <summary>
32  /// (CastTo)Expression
33  /// </summary>
34  public class CastExpression : Expression
35  {
36    public CSharpTokenNode LParToken {
37      get { return GetChildByRole (Roles.LPar); }
38    }
39   
40    public AstType Type {
41      get { return GetChildByRole (Roles.Type); }
42      set { SetChildByRole (Roles.Type, value); }
43    }
44   
45    public CSharpTokenNode RParToken {
46      get { return GetChildByRole (Roles.RPar); }
47    }
48   
49    public Expression Expression {
50      get { return GetChildByRole (Roles.Expression); }
51      set { SetChildByRole (Roles.Expression, value); }
52    }
53   
54    public CastExpression ()
55    {
56    }
57
58    public CastExpression (AstType castToType, Expression expression)
59    {
60      AddChild (castToType, Roles.Type);
61      AddChild (expression, Roles.Expression);
62    }
63
64    public override void AcceptVisitor (IAstVisitor visitor)
65    {
66      visitor.VisitCastExpression (this);
67    }
68     
69    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
70    {
71      return visitor.VisitCastExpression (this);
72    }
73   
74    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
75    {
76      return visitor.VisitCastExpression (this, data);
77    }
78   
79    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
80    {
81      CastExpression o = other as CastExpression;
82      return o != null && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match);
83    }
84
85    #region Builder methods
86    public override MemberReferenceExpression Member(string memberName)
87    {
88      return new MemberReferenceExpression { Target = this, MemberName = memberName };
89    }
90
91    public override IndexerExpression Indexer(IEnumerable<Expression> arguments)
92    {
93      IndexerExpression expr = new IndexerExpression();
94      expr.Target = new ParenthesizedExpression(this);
95      expr.Arguments.AddRange(arguments);
96      return expr;
97    }
98
99    public override IndexerExpression Indexer(params Expression[] arguments)
100    {
101      IndexerExpression expr = new IndexerExpression();
102      expr.Target = new ParenthesizedExpression(this);
103      expr.Arguments.AddRange(arguments);
104      return expr;
105    }
106
107    public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
108    {
109      InvocationExpression ie = new InvocationExpression();
110      MemberReferenceExpression mre = new MemberReferenceExpression();
111      mre.Target = new ParenthesizedExpression(this);
112      mre.MemberName = methodName;
113      mre.TypeArguments.AddRange(typeArguments);
114      ie.Target = mre;
115      ie.Arguments.AddRange(arguments);
116      return ie;
117    }
118
119    public override InvocationExpression Invoke(IEnumerable<Expression> arguments)
120    {
121      InvocationExpression ie = new InvocationExpression();
122      ie.Target = new ParenthesizedExpression(this);
123      ie.Arguments.AddRange(arguments);
124      return ie;
125    }
126
127    public override InvocationExpression Invoke(params Expression[] arguments)
128    {
129      InvocationExpression ie = new InvocationExpression();
130      ie.Target = new ParenthesizedExpression(this);
131      ie.Arguments.AddRange(arguments);
132      return ie;
133    }
134
135    public override CastExpression CastTo(AstType type)
136    {
137      return new CastExpression { Type = type,  Expression = new ParenthesizedExpression(this) };
138    }
139
140    public override AsExpression CastAs(AstType type)
141    {
142      return new AsExpression { Type = type,  Expression = new ParenthesizedExpression(this) };
143    }
144
145    public override IsExpression IsType(AstType type)
146    {
147      return new IsExpression { Type = type,  Expression = new ParenthesizedExpression(this) };
148    }
149    #endregion
150  }
151}
152
Note: See TracBrowser for help on using the repository browser.