~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
 
 
7
namespace ICSharpCode.NRefactory.VB.Ast
 
8
{
 
9
        public abstract class Expression : AstNode
 
10
        {
 
11
                #region Null
 
12
                public new static readonly Expression Null = new NullExpression ();
 
13
                
 
14
                sealed class NullExpression : Expression
 
15
                {
 
16
                        public override bool IsNull {
 
17
                                get {
 
18
                                        return true;
 
19
                                }
 
20
                        }
 
21
                        
 
22
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
23
                        {
 
24
                                return default (S);
 
25
                        }
 
26
                        
 
27
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
28
                        {
 
29
                                return other == null || other.IsNull;
 
30
                        }
 
31
                }
 
32
                #endregion
 
33
                
 
34
                #region Builder methods
 
35
                /// <summary>
 
36
                /// Builds an member reference expression using this expression as target.
 
37
                /// </summary>
 
38
                public MemberAccessExpression Member(string memberName)
 
39
                {
 
40
                        return new MemberAccessExpression { Target = this, MemberName = memberName };
 
41
                }
 
42
                
 
43
                /// <summary>
 
44
                /// Builds an invocation expression using this expression as target.
 
45
                /// </summary>
 
46
                public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
 
47
                {
 
48
                        return Invoke(methodName, null, arguments);
 
49
                }
 
50
                
 
51
                /// <summary>
 
52
                /// Builds an invocation expression using this expression as target.
 
53
                /// </summary>
 
54
                public InvocationExpression Invoke(string methodName, params Expression[] arguments)
 
55
                {
 
56
                        return Invoke(methodName, null, arguments);
 
57
                }
 
58
                
 
59
                /// <summary>
 
60
                /// Builds an invocation expression using this expression as target.
 
61
                /// </summary>
 
62
                public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
 
63
                {
 
64
                        InvocationExpression ie = new InvocationExpression();
 
65
                        MemberAccessExpression mre = new MemberAccessExpression();
 
66
                        mre.Target = this;
 
67
                        mre.MemberName = methodName;
 
68
                        mre.TypeArguments.AddRange(typeArguments);
 
69
                        ie.Target = mre;
 
70
                        ie.Arguments.AddRange(arguments);
 
71
                        return ie;
 
72
                }
 
73
                
 
74
                /// <summary>
 
75
                /// Builds an invocation expression using this expression as target.
 
76
                /// </summary>
 
77
                public InvocationExpression Invoke(IEnumerable<Expression> arguments)
 
78
                {
 
79
                        InvocationExpression ie = new InvocationExpression();
 
80
                        ie.Target = this;
 
81
                        ie.Arguments.AddRange(arguments);
 
82
                        return ie;
 
83
                }
 
84
                
 
85
                /// <summary>
 
86
                /// Builds an invocation expression using this expression as target.
 
87
                /// </summary>
 
88
                public InvocationExpression Invoke(params Expression[] arguments)
 
89
                {
 
90
                        InvocationExpression ie = new InvocationExpression();
 
91
                        ie.Target = this;
 
92
                        ie.Arguments.AddRange(arguments);
 
93
                        return ie;
 
94
                }
 
95
                
 
96
                public CastExpression CastTo(AstType type)
 
97
                {
 
98
                        return new CastExpression { CastType = CastType.CType, Type = type,  Expression = this };
 
99
                }
 
100
                
 
101
                public CastExpression CastTo(Type type)
 
102
                {
 
103
                        return new CastExpression { CastType = CastType.CType, Type = AstType.Create(type),  Expression = this };
 
104
                }
 
105
                #endregion
 
106
        }
 
107
}